PDA

View Full Version : Sorting



pedro_gb
Mon 17th Jul '00, 7:05pm
I may be asking too much (I don't have vBulletin...yet!) but one very good feature that could exist is sorting. I'm sure a lot of people will want this kind of feature and I am also sure that this would require a lot of work. I am almost clueless on PHP so I can't know how to do this. The sorting I am talking about is Hotmail style (for example: You can click in the 'thread' text in the top of the screen so that is sorts all the threads from A-Z the first time you click it and Z-A the second time you click it. How do you like this idea? You would DEFINATELY get a new customer if you get this feature in the next version. By the way, when is the next major version expected to see if I can catch the bus?

Martin
Mon 17th Jul '00, 7:33pm
something like that is supposed to be on the "to do" list.

also, no release date on the next major version.

Freddie Bingham
Mon 17th Jul '00, 7:47pm
So you want to sort the threads alphabetically (or reverse) instead of by Date?

That would be an easy thing to do.

You would just make a link that calls this code in forumdisplay.php



$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postuserna me,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY title DESC LIMIT $limitlower,$perpage");


Changce the 'DESC' to 'ASC' to switch the order around.

Dave Baker
Mon 17th Jul '00, 11:23pm
Thanks, rangersfan -- here's what I did in forumdisplay.php:

Old:

$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postuserna me,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY lastpost DESC LIMIT $limitlower,$perpage");

New:

if (isset($sortbyviews)==0 or $sortbyviews=="no") {
$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postuserna me,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY lastpost DESC LIMIT $limitlower,$perpage");
} else {
$threads=$DB_site->query("SELECT threadid,title,open,lastpost,replycount,postuserna me,lastposter,notes,iconid,views FROM thread WHERE forumid=$forumid AND visible=1 $datecut ORDER BY views DESC LIMIT $limitlower,$perpage");
}

Now I'll figure out how to add a &sortbyviews=yes to the URL when somebody wants to sort by the number of times the message threads have been viewed, and how to get rid of &sortbyviews=yes (or set it to &sortbyviews=no) if they want the standard date-order display. Kewl!

[Edited by Dave Baker on 07-18-2000 at 12:39 AM]

Dave Baker
Mon 17th Jul '00, 11:49pm
Otay, that wasn't hard -- here's what I did to my forumdisplay template (partial excerpt):

<table border="0" cellpadding="4" cellspacing="1" width="100%">
<tr bgcolor="#113274">
<td colspan="2" align="center" width="60%">
<smallfont color="#FFFFFF"><B>Name of Thread (Topic)</B></smallfont>
</td>
<td align="center" width="10%"><smallfont color="#FFFFFF"><B>Started By</B></smallfont>
</td>
<td align="center" width="5%"><smallfont color="#FFFFFF"><B>Reply<br>Messages</B></smallfont>
</td>
<td align="center" width="5%"><smallfont color="#FFFFFF"><B><a href="forumdisplay.php3?forumid=$forumid&daysprune=$daysprune&sortbyviews=yes">Total<br>Views</a></B></smallfont>
</td>
<td align="center" width="20%">
<smallfont color="#FFFFFF"><B><a href="forumdisplay.php3?forumid=$forumid&daysprune=$daysprune&sortbyviews=no">Newest Message<br>In Thread</a></B></smallfont>
</td></tr>
$announcement
$forumdisplaybits
---------------------------------------

Probably also a good thing to add the new $sortbyviews variable (shown in bold) to these lines in forumdisplay.php, so we keep our sorting preference when going to a subsequent page in a multi-page results list:

if (($curpage<$pagenumber-$pagenavpages or $curpage>$pagenumber+$pagenavpages) and $pagenavpages!=0) {
if ($curpage==1) {
$pagenav.=" <a href=\"forumdisplay.php3?forumid=$forumid&daysprune=$daysprune&sortbyviews=$sortbyviews&pagenumber=$curpage".iif($perpage==$maxposts,"","&perpage=$perpage")."\">&lt;&lt; First Page</a> ... ";
}
if ($curpage==$totalpages) {
$pagenav.=" ... <a href=\"forumdisplay.php3?forumid=$forumid&daysprune=$daysprune&sortbyviews=$sortbyviews&pagenumber=$curpage".iif($perpage==$maxposts,"","&perpage=$perpage")."\">Last Page &gt;&gt;</a>";
}
} else {
if ($curpage==$pagenumber) {
$pagenav.=" $curpage";
} else {
$pagenav.=" <a href=\"forumdisplay.php3?forumid=$forumid&daysprune=$daysprune&sortbyviews=$sortbyviews&pagenumber=$curpage".iif($perpage==$maxposts,"","&perpage=$perpage")."\">$curpage</a>";
}
}


Now the user can sort by views by clicking on the "Total Views" table heading, and can get back to a sort by date (the default) by clicking on the "Newest Message in Thread" table heading.

[Edited by Dave Baker on 07-24-2000 at 05:12 PM]