Hey, i've run into a bit of a problem which i can't seem to solve. Basically i'm making a forum and i'm working on a section that enables you to view information about the other users signed up the forum in one big table. I have 6 columns and a listbox that enables you to sort the data regarding the selected item chosen (ie. if postcount is chosen the table will be sorted by post count) Anyway, here's my code for the listbox:
<select name="menusortby" id="menusortby" onChange="MM_jumpMenu('parent',this,0)">
<option value=""></option>
<option value="ForumViewAllMembers.php?sortby=0">Member Username</option>
<option value="ForumViewAllMembers.php?sortby=1">Member Since</option>
<option value="ForumViewAllMembers.php?sortby=2">Post Count</option>
<option value="ForumViewAllMembers.php?sortby=3">Last Active Date</option>
<option value="ForumViewAllMembers.php?sortby=4">Last Post Date</option>
<option value="ForumViewAllMembers.php?sortby=5">Last Post Title</option>
</select>
As you can see, a variable 'sortby' is assigned a value regarding the option chosen. Depending on what the variable holds will depend what sql query is run: heres my php:
<?php
$sort = ($_GET['sortby']);
if ($sort=0) {
$result = mysql_query("SELECT * FROM Forum_Users ORDER BY username",$connection);
}
if ($sort=1) {
$result = mysql_query("SELECT * FROM Forum_Users ORDER BY membersince",$connection);
}
if ($sort=2) {
$result = mysql_query("SELECT * FROM Forum_Users ORDER BY postcount DESC",$connection);
}
if ($sort=3) {
$result = mysql_query("SELECT * FROM Forum_Users ORDER BY lastactivedate DESC",$connection);
}
if ($sort=4) {
$result = mysql_query("SELECT * FROM Forum_Users ORDER BY lastpostdate DESC",$connection);
}
if ($sort=5) {
$result = mysql_query("SELECT * FROM Forum_Users ORDER BY lastpostsubject",$connection);
}
while ($row=mysql_fetch_array($result)){
$uname = $row['username'];
$membersince = $row['membersince'];
$postcount = $row['postcount'];
$lastactivedate = $row['lastactivedate'];
$lastpostdate = $row['lastpostdate'];
$lastposttitle = $row['lastpostsubject'];
$displayblock .= "<tr><td><div align='center'>$uname</div></td><td><div align='center'>$membersince</div></td><td><div align='center'>$postcount</div></td><td><div align='center'>$lastactivedate</div></td><td><div align='center'>$lastpostdate</div></td><td><div align='center'>$lastposttitle</div></td></tr>";
}
echo $displayblock;
?>
I know my choice of if loops is inefficient but i'm unsure of another way to do it. Anyway, the problem i have is that whatever option is chosen, the table still will not sort and i can't figure out why. Like if you choose postcount, you can see it should sort the table in descending order but it doesn't. Sorry if this is a bit complicated but i just cant figure it out so if anyone can see something wrong with this, please tell me.
Thank you, BIOSTALL