It would be cool if you make it so that if you click it sorts ascending and if you click again it sorts descending
One remark though:
The following code can be much shorter:
Code:
if($sortbyreply=="yes"){
$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postusername,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY replycount DESC LIMIT $limitlower,$perpage");
}elseif($sortbyviews=="yes"){
$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postusername,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY views DESC LIMIT $limitlower,$perpage");
} elseif($sortbyuser=="yes"){
$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postusername,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY postusername asc LIMIT $limitlower,$perpage");
}elseif($sortbytitle=="yes"){
$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postusername,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY threadid DESC LIMIT $limitlower,$perpage");
}else {
$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postusername,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY lastpost DESC LIMIT $limitlower,$perpage");
}
better:
Code:
if(empty($orderField))
$orderField = "lastpost";
$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postusername,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY $orderField DESC LIMIT $limitlower,$perpage");
And then make orderfield the variable to use within the links, example:
forumdisplay.php?forumid=$forumid&daysprune=$daysp rune&orderField=lastpost
or something like that. This way you don't have to alter the code if you want another field against to order, just make a link with orderField="anyFieldYouWant" and it works (provided that the field exists within the table)
[Edited by Mas*Mind on 09-08-2000 at 04:58 AM]