]> ruin.nu Git - ndwebbie.git/blobdiff - forum.pl
order by last post
[ndwebbie.git] / forum.pl
index cdd51fec478d0ac40bb4047a133da8bb831b483e..e006b201cfc39418eb4c0b8793273e2fb4496c16 100644 (file)
--- a/forum.pl
+++ b/forum.pl
@@ -61,11 +61,12 @@ if (defined param('cmd') && param('cmd') eq 'forumpost'){
 }
 
 my $categories = $DBH->prepare(q{SELECT fcid AS id,category FROM forum_categories ORDER BY fcid});
-my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts
+my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts, max(fp.time)::timestamp as last_post
 FROM forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
 WHERE ft.fbid = $1
 GROUP BY ft.ftid, ft.subject
-HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= $3});
+HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= $3
+ORDER BY last_post DESC});
 
 if ($thread){ #Display the thread
        $BODY->param(Thread => viewForumThread $thread);
@@ -94,6 +95,7 @@ FROM forum_boards fb NATURAL JOIN forum_access fa
 WHERE fb.fcid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
        WHERE uid = $2))
 GROUP BY fb.fbid,fb.board
+ORDER BY fb.fbid
 });
        while (my $category = $categories->fetchrow_hashref){
                $boards->execute($category->{id},$ND::UID) or $ERROR .= p($DBH->errstr);