need urgent help
Moderator: General Moderators
need urgent help
please I need someone to help
I need a code for sorting categories in the index page
i retrive data from table
$query1 = "SELECT * FROM users WHERE category='Arts' ;
Now I have many links
<li><a href="#">News</a></li>
<li><a href="#">Sports</a></li>
<li><a href="#">Jokes</a></li>
I want to click on the link news to sort the table to News
and so on
this this could be done?
I need a code for sorting categories in the index page
i retrive data from table
$query1 = "SELECT * FROM users WHERE category='Arts' ;
Now I have many links
<li><a href="#">News</a></li>
<li><a href="#">Sports</a></li>
<li><a href="#">Jokes</a></li>
I want to click on the link news to sort the table to News
and so on
this this could be done?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: need urgent help
You need to pass the value according to which you want to sort along in a query string.
Then you need to retrieve the value
Make sure it's sanitize (cleaned-up) before using it inside your query
Use this as an idea and create your own script and paste it if you need more help. Hth
Code: Select all
<li><a href="page.php?value=News">News</a></li>Code: Select all
<?php $value = $_GET['value']; ?>Code: Select all
<?php
$value = $_GET['value'];
$query = mysql_query("SELECT fields FROM table ORDER BY ". $value ." ");
// display the results
while ($array = mysql_fetch_array($query)) {
// show results
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: need urgent help
I'm not sure I understand your problem fully, but I'll give it a go.
I would do something like this;
lol you're lucky, I got in to it and decided to write a full example. (untested)
I would do something like this;
Code: Select all
<style type="text/css">
a.news {}
a.sports {display: none;}
a.jokes {display: none;}
#news {position:absolute; top:50px; left:0px;}
#sports {position:absolute; top:50px; left:0px;}
#jokes {position:absolute; top:50px; left:0px;}
</style>
<script type="text/javascript" src="jquery_1_4_4.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//Click event on news
$("#nav_bar a .news").click(function() { //Click on news and...
$('#news').show(); // show news panel
$("#sports").hide(); //hide sports panel
$("#jokes").hide(); //hide jokes panel
});
//Click event on sports
$("#nav_bar a .sports").click(function() { //Click on news and...
$('#news').hide(); // hide news panel
$("#sports").show(); //hide sports panel
$("#jokes").hide(); //hide jokes panel
});
//Click event on jokes
$("#nav_bar a .jokes").click(function() { //Click on news and...
$('#news').hide(); // hide news panel
$("#sports").hide(); //hide sports panel
$("#jokes").show(); //show jokes panel
});
});
</script>
<?php
include ('connecttodb.php');
$query1 = "SELECT * FROM news"; // I am assuming that this will select all the news stories
$query2 = "SELECT * FROM sports"; // I am assuming that this will select all the sports stories
$query3 = "SELECT * FROM jokes"; // I am assuming that this will select all the jokes
$result1 = mysql_query($query1);
$result2 = mysql_query($query2);
$result3 = mysql_query($query3);
$num1=mysql_num_rows($result1);
$num2=mysql_num_rows($result2);
$num3=mysql_num_rows($result3);
echo '<div id="nav_bar">';
echo '<a href="#" class="news">News</a>';
echo '<a href="#" class="sports">Sports</a>';
echo '<a href="#" class="jokes">Jokes</a>';
echo '</div>';
echo '<div id="news">';
$i=0;
while ($i < $num1) {
$row1 = mysql_result($result1);
$row1assoc = mysql_fetch_array($row1, MYSQL_ASSOC);
echo '<li class="title">' . $row1assoc['title'] . '</li><br />';
echo '<li class="content">' . $row1assoc['content'] . '</li><br />';
$i++;
}
echo '</div>';
echo '<div id="sports">';
$j=0;
while ($j < $num2) {
$row2 = mysql_result($result2);
$row2assoc = mysql_fetch_array($row2, MYSQL_ASSOC);
echo '<li class="title">' . $row2assoc['title'] . '</li><br />';
echo '<li class="content">' . $row2assoc['content'] . '</li><br />';
$j++;
}
echo '</div>';
echo '<div id="jokes">';
$k=0;
while ($k < $num3) {
$row3 = mysql_result($result3);
$row3assoc = mysql_fetch_array($row3, MYSQL_ASSOC);
echo '<li class="title">' . $row3assoc['title'] . '</li><br />';
echo '<li class="content">' . $row3assoc['content'] . '</li><br />';
$k++;
}
echo '</div>';
?>
Last edited by Neilos on Tue Jan 04, 2011 5:21 pm, edited 3 times in total.
Re: need urgent help
damn my code is good looking, and all in 30 mins!
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: need urgent help
It looks like he wants to order his resultsphppro62 wrote:I want to click on the link news to sort the table to News
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: need urgent help
lol it's all good practice. It's a little confusing what he wants from his question.
lol
Now I would say that means, he gets lots of news stories and he wants to display a list of news stories instead of jokes or sports stories.phppro62 wrote: I want to click on the link news to sort the table to News
I have no idea what this means, apart from the sql command itself, what it actually pulls is a mysteryphppro62 wrote: $query1 = "SELECT * FROM users WHERE category='Arts' ;
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: need urgent help
True, if you look at the verb sort it seems that he is implying to order somehow and from the SELECT query it looks like he wants everything displayed.Neilos wrote:It's a little confusing what he wants from his question.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: need urgent help
lol fixedsocial_experiment wrote:mysql_num_rows() instead of mysql_numrows()
Re: need urgent help
Maybe, but until we get some clarification on what he is doing and/or wants we'll not know. It's like fishing, now is the waiting game!social_experiment wrote:True, if you look at the verb sort it seems that he is implying to order somehow and from the SELECT query it looks like he wants everything displayed.Neilos wrote:It's a little confusing what he wants from his question.
Re: need urgent help
hi mates
thanks all for your time and efforts
I'll try to clarify what I need .
i have one page called index.php
i make this page dynamic using php and mysql
the page now is displaying data from the table users orderded by timesofsubmit, Des
there are submission for many categories such as News Arts Music and so on
I have nav bar that has text link <a href="#">News</a>
I want to make this link change the displaying data with (WHERE category='News')
I can do it for the loading of the page but don't know how to change it dynamically when there is a click on the link "News" to change from another category to what i want.
I hope that i clarify what i need
I can make it by pages every link directed to another page and display like news.php
but this is not a pratical way and takes time
thanks all for your time and efforts
I'll try to clarify what I need .
i have one page called index.php
i make this page dynamic using php and mysql
the page now is displaying data from the table users orderded by timesofsubmit, Des
there are submission for many categories such as News Arts Music and so on
I have nav bar that has text link <a href="#">News</a>
I want to make this link change the displaying data with (WHERE category='News')
I can do it for the loading of the page but don't know how to change it dynamically when there is a click on the link "News" to change from another category to what i want.
I hope that i clarify what i need
I can make it by pages every link directed to another page and display like news.php
but this is not a pratical way and takes time
Re: need urgent help
Hi mates again
II tried the way that social_experiment gave me .
Yes it's working
Thsank you very much
II tried the way that social_experiment gave me .
Yes it's working
Thsank you very much