Yes, that's right. We need to add "GROUP BY" and one "iff" to the SQL query.
my code (in forumdisplay.php)
PHP Code:
// gallery hack
if (in_array($forumid, $forumids)) {
$displaythumbs = true;
}
$sql_threads = "
SELECT $votequery $previewfield
thread.threadid, thread.title AS threadtitle, thread.forumid, pollid, open, replycount, postusername, postuserid, thread.iconid AS threadiconid,
$lastpost_info, thread.dateline, IF(views<=replycount, replycount+1, views) AS views, notes, thread.visible, sticky, votetotal, thread.attach "
. iif($displaythumbs == true, ", attachment.attachmentid AS attachmentid ")
. iif($vbulletin->options['threadsubscribed'] AND $vbulletin->userinfo['userid'], ", NOT ISNULL(subscribethread.subscribethreadid) AS issubscribed")
. iif($deljoin, ", deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason")
. iif($vbulletin->options['threadmarking'] AND $vbulletin->userinfo['userid'], ', threadread.readtime AS threadread') . "
FROM " . TABLE_PREFIX . "thread AS thread
$deljoin
" . iif($vbulletin->options['threadsubscribed'] AND $vbulletin->userinfo['userid'], " LEFT JOIN " . TABLE_PREFIX . "subscribethread AS subscribethread ON(subscribethread.threadid = thread.threadid AND subscribethread.userid = " . $vbulletin->userinfo['userid'] . ")") . "
" . iif($vbulletin->options['threadmarking'] AND $vbulletin->userinfo['userid'], " LEFT JOIN " . TABLE_PREFIX . "threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = " . $vbulletin->userinfo['userid'] . ")") . "
$previewjoin
" . iif($displaythumbs == true, "LEFT JOIN ".TABLE_PREFIX."attachment as attachment ON(attachment.postid = thread.firstpostid) "). "
$tachyjoin
WHERE thread.threadid IN (0$ids)"
. iif($displaythumbs == true, "GROUP BY attachment.postid ") ."
ORDER BY sticky DESC, $sqlsortfield $sqlsortorder
";
$threads=$db->query_read($sql_threads);
//end of gallery hack
Check it :)
|