PDA


View Full Version : latesttopics.php error on sort by "rating"


fyjpm
12-09-2005, 02:26 AM
Hi I've come across what I believe is a bug in lastesttopics.php when you use the "Thread Display Order" => "Rating" the following error is returned:

Database error in vBulletin 3.5.2:

Invalid SQL:

SELECT

thread.threadid, thread.title, thread.replycount, postusername, postuserid, thread.dateline AS postdateline, IF(views <= thread.replycount, thread.replycount+1, views) AS views, thread.lastposter, thread.lastpost, pollid

FROM vb_thread as thread
LEFT JOIN vb_deletionlog AS deletionlog ON (thread.threadid = deletionlog.primaryid AND type = 'thread')
WHERE open != 10 AND thread.visible = 1



AND deletionlog.primaryid IS NULL
ORDER BY voteavg DESC
LIMIT 5;

MySQL Error : Unknown column 'voteavg' in 'order clause'
Error Number : 1054

the affected code is on line 79 (or perhaps 133 if a divide by zero error?) here is line 77,78, & 79:

$threads = $db->query_read("
SELECT
" . iif($mod_options['portal_threads_showrating'], 'IF(votenum >= ' . $vbulletin->options['showvotes'] . ', votenum, 0) AS n
umbvote, IF(votenum >= ' . $vbulletin->options['showvotes'] . ' AND votenum != 0, votetotal / votenum, 0) AS voteavg,') . "


(might I add some pretty funny looking "if" statements!!) Anyone have some info to get this fixed would be much appreciated! Thanks,

John

fyjpm
12-09-2005, 02:29 AM
Can someone else see if they can duplicate this? Perhaps it is due to the fact that some of my threads do not have any ratings? ...trying to figure it out still

fyjpm
12-09-2005, 02:41 AM
I solved it. It actually is a bug, but not very hard to fix. YOU MUST HAVE "Show Thread Ratings" set to "yes" or you get the error. The code probably need a sanity check here to prevent the unknowing user from encountering the same error. Anyways - I have sort by rating now working.. no help like self help LOL

-John

Brian
12-09-2005, 04:38 PM
Thanks for pointing that out. If you'd like to correct the problem without turning on the ratings display, just look in your modules/latesttopics.php file for this code:
iif($mod_options['portal_threads_showrating']

Replace with this:
iif($mod_options['portal_threads_showrating'] OR $mod_options['portal_threads_orderby'] == 'voteavg'

And that should take care of the problem.