PDA

View Full Version : [RELEASE] Multiple Sorting Hack


09-07-2000, 11:38 PM
Hi,

Here is my first hack. (that doesn't necessarily mean it will not work) :D

It is partially based on Dave Baker hack here:
http://vbulletin.com/forum/showthread.php?threadid=1853


This hack will simply enable users to sort threads by four additional ways:
1- Number of replies.
2- Number of viewers
3- Alphabetical order of poster names
4- Threadid , this will make threads ordered by the newest topic regardless of the last reply date.



ok, and now what you need to change :)


look for this line in forumdiplay.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 lastpost DESC LIMIT $limitlower,$perpage");


Then replace it with:

if($sortbyreply=="yes"){
$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 replycount DESC LIMIT $limitlower,$perpage");
}elseif($sortbyviews=="yes"){
$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");
} elseif($sortbyuser=="yes"){
$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 postusername asc LIMIT $limitlower,$perpage");
}elseif($sortbytitle=="yes"){
$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 threadid 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 lastpost DESC LIMIT $limitlower,$perpage");
}




In the same file above (forumdisplay.php) add whats in bold:



while ($curpage++<$totalpages) {

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



And finally in forumdisplay template add whats in Bold (again):



<table border="0" cellpadding="4" cellspacing="1" width="100%">
<tr bgcolor="#113274">
<td colspan="2" align="center" width="60%">
<a href="forumdisplay.php?forumid=$forumid&daysprune=$daysprune&sortbytitle=yes">
<FONT face="verdana,arial,helvetica" size="1" color="#FFFFFF"><B>
Name of Thread (Topic)</B></font>
</a>
</td>
<td align="center" width="10%">
<a href="forumdisplay.php?forumid=$forumid&daysprune=$daysprune&sortbyuser=yes">
<FONT face="verdana,arial,helvetica" size="1" color="#FFFFFF"><B>Started By</B></font>
</a>
</td>
<td align="center" width="5%">
<a href="forumdisplay.php?forumid=$forumid&daysprune=$daysprune&sortbyreply=yes">
<FONT face="verdana,arial,helvetica" size="1" color="#FFFFFF"><B>Reply<br>Messages</B></font>
</a>
</td>
<td align="center" width="5%">
<a href="forumdisplay.php?forumid=$forumid&daysprune=$daysprune&sortbyviews=yes">
<FONT face="verdana,arial,helvetica" size="1" color="#FFFFFF"><B>
Total<br>Views</B></font>
</a>
</td>
<td align="center" width="20%">
<a href="forumdisplay.php?forumid=$forumid&daysprune=$daysprune">
<FONT face="verdana,arial,helvetica" size="1" color="#FFFFFF"><B>Newest Message<br>In Thread</B></font>
</a>
</td></tr>



Thats it. Hope you like it. :)

09-07-2000, 11:48 PM
that's great! do you have a working demo?

09-08-2000, 04:07 AM
Hello,

I tried SOrt by Title...it does not work...it brings back some order...just not alphabetical...

Everything else works..

One Thing. It does not sort by Last post...it just brings you to the regular forumdisplay. Is that on purpose or did you forget to add code.

Question: Does this hack have any resource or efficiency issues with mysql or the server on high usage?

Great Hack. Thanks. :)

[Edited by VirtueTech on 09-08-2000 at 01:14 AM]

09-08-2000, 04:32 AM
Conan,

You can see VirtueTech's forum. Mine is not in English so it might be hard to see whats going on. :)



VirtueTech,

As I said, sort by title does NOT sort treads alphabeticly (cause I thought it might be useless). It sorts them by the date of the first post in that thread (the main post). You can check'em out yourself and see the dates. If you want to make it sort alphabeticly, just replace.


$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 threadid DESC LIMIT $limitlower,$perpage");


with


$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");



Regular forumdisplay actually does sort threads by last post :) I added it so that people can get back to normal sorting.

I cannot answer your last question cause I'm not that experinced. One of the guys might have an answer.





[Edited by Essam on 09-08-2000 at 01:37 AM]

09-08-2000, 04:39 AM
Hello,

Sorry in my excited rave I forgot to read the part about threadid...Lots of users are going to get confused when they see the Threads sort not alphabetcal...same with Last Post sort.

Maybe I'm wrong.

09-08-2000, 04:52 AM
What would be really cool is if you could sort by ascending then click on it again and it sorts by descending.

Then we would need a down arrow and up arrow...for the two...like Outlook does its sorting.

09-08-2000, 07:56 AM
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:

if($sortbyreply=="yes"){
$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 replycount DESC LIMIT $limitlower,$perpage");
}elseif($sortbyviews=="yes"){
$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");
} elseif($sortbyuser=="yes"){
$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 postusername asc LIMIT $limitlower,$perpage");
}elseif($sortbytitle=="yes"){
$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 threadid 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 lastpost DESC LIMIT $limitlower,$perpage");
}

better:


if(empty($orderField))
$orderField = "lastpost";
$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 $orderField DESC LIMIT $limitlower,$perpage");


And then make orderfield the variable to use within the links, example:

forumdisplay.php?forumid=$forumid&daysprune=$daysprune&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]

09-08-2000, 08:27 AM
Well not all the sorts are descending ... your code would make it that way :) But a good idea!

A good example of one click is ascending and the next click is descending is at a medical site I'm working on:

http://www.medinfolinks.com/cgi-local/pharmacy/detail.cgi?ID=5

Also notice how the Sort by Arrow graphics changes on each column.

This would be a great feature to have.

09-08-2000, 06:59 PM
Does this hack cause any server load issues with mysql or just the same as a regular forum display process?