vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   [RELEASE] Multiple Sorting Hack (https://vborg.vbsupport.ru/showthread.php?t=3030)

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:
Code:

$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");
Then replace it with:
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");
}



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

Code:


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):
Code:



<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.

Code:

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


$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 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:

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]

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-loca...etail.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?


All times are GMT. The time now is 09:23 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01340 seconds
  • Memory Usage 1,754KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete