Topic: Sorting Topics Choice Not Functioning

There doesn't seem to be any change at all to the forum when you switch back and forth between organize forum by "last post" or "topic start".  Unless I"m not understanding what this is supposed to do.  My assumption was that if I have it set to "topic start" and I have a topic called "1 blah blah blah" that it would always be first in the list and something called "2 blah blah blah" in would be second, and so on.  I also tried a post with a word starting with "a" with the other posts starting with other letters and it still doesn't display it at the top.  Am I missing something?

2 (edited by CodeXP 2005-06-14 22:39)

Re: Sorting Topics Choice Not Functioning

Yes, you're missing something wink

Organize forum by topic start = Sort by the date when topic was first started.
Organize forum by last post = Sort by the date of the last post in any given topic.

Re: Sorting Topics Choice Not Functioning

ahhhh....yes I understand now.  I am still searching then for a way to organize posts differently and haven't found a solution yet.  For example, a way to organize them in reverse order, with the oldest at top and most recent at bottom.  I need this for a "read-only" forum I'm creating next to my other regular forums.

Re: Sorting Topics Choice Not Functioning

Ok, I made a little hack for you that gives you the option to sort with the oldest topic start date at the top, and the newest at the bottom:

Open admin_forums.php

Around line 284, find:

<option value="1"<?php if ($cur_forum['sort_by'] == '1') echo ' selected="selected"' ?>>Topic start</option>

After, add:

<option value="2"<?php if ($cur_forum['sort_by'] == '2') echo ' selected="selected"' ?>>Topic start, reverse</option>

Open viewforum.php

Around line 109, find:

// Fetch list of topics to display on this page

After, add:

if (($cur_forum['sort_by'] == '1') || ($cur_forum['sort_by'] == '0')) {
    $newsort = 'DESC';
} else if ($cur_forum['sort_by'] == '2') {
    $newsort = 'ASC';
}

Around line 117, find

    // Without "the dot"
    $sql = 'SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];

Replace with:

    // Without "the dot"
    $sql = 'SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' '.$newsort.' LIMIT '.$start_from.', '.$pun_user['disp_topics'];

Around line 126, find:

        case 'mysqli':
            $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];
            break;

        case 'sqlite':
            $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.id IN(SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'].') GROUP BY t.id ORDER BY t.sticky DESC, t.last_post DESC';
            break;

        default:
            $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to, p.poster_id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' DESC LIMIT '.$start_from.', '.$pun_user['disp_topics'];
            break;

Replace with:

        case 'mysqli':
            $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' '.$newsort.' LIMIT '.$start_from.', '.$pun_user['disp_topics'];
            break;

        case 'sqlite':
            $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.id IN(SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$id.' ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' '.$newsort.' LIMIT '.$start_from.', '.$pun_user['disp_topics'].') GROUP BY t.id ORDER BY t.sticky DESC, t.last_post DESC';
            break;

        default:
            $sql = 'SELECT p.poster_id AS has_posted, t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.poster_id='.$pun_user['id'].' WHERE t.forum_id='.$id.' GROUP BY t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to, p.poster_id ORDER BY sticky DESC, '.(($cur_forum['sort_by'] == '1') ? 'posted' : 'last_post').' '.$newsort.' LIMIT '.$start_from.', '.$pun_user['disp_topics'];
            break;

Save & upload

Now you can sort by topic start in reverse smile

Re: Sorting Topics Choice Not Functioning

Wow, that's great - thanks for coming up with all that.  My only question, prior to implementing it, is will that change the sorting on a global scale?  I am looking to change the sort order for just one forum, not for all forums running under this copy of PunBB.

Re: Sorting Topics Choice Not Functioning

No

Re: Sorting Topics Choice Not Functioning

That worked great, thanks very much.  I think this is a great add to the software and something that should be permanantly incorporated into it for everyone.  More choices of sorting = better!

Thanks again!

Re: Sorting Topics Choice Not Functioning

Added to the punres wiki smile http://punres.org/doku.php?id=how-tos:r … _of_topics

9 (edited by minusf 2005-06-29 20:43)

Re: Sorting Topics Choice Not Functioning

is there a chance this gets into the next version?
i mean reversing the other of the posts seems like quite a basic function to me...

even better, make it a user option.  every user has his/her preference in what order to watch the posts, don't they?

Re: Sorting Topics Choice Not Functioning

i seriously doubt even 1% of punbb users want to see the oldest topic first and the newest topic last

11

Re: Sorting Topics Choice Not Functioning

no no, it's a misunderstanding.
i am not talking about the topics, but the replies in a particular topic....

and those, no matter what you do last post is always the last.

12

Re: Sorting Topics Choice Not Functioning

I understand the logic. I'm sitting here now looking through a file of correspondence which, as is normal, has the latest correspondence on the top of the file so you start reading from today and work back. Thats how most businesses and certainly professions organize their correspondence and documents. Whether that is appropriate for a forum rather depends on the nature of the thread being read.

13

Re: Sorting Topics Choice Not Functioning

ahh yes, but you're assuming everyone uses PunnBB the same way.  I originally requested it so that I could use a specific forum for FAQ's.  I've got the most important and common FAQ's at the top, which I posted first, and then as smaller ones come up along the way, I add them.  I wanted to make sure that when I added them, they went to the bottom of the list, not the top so that the list remained in order of importance.  That particular one is a read-only forum, mixed in with the other regular forums that I want sorted in the normal most-recent-at-top order.
this hack gives me the option of setting the read-only FAQ forum to list topics with oldest (and most important) at that top.
An ideal scenario would be for an admin to have the ability to physically move topics around within a forum - like a "move to top" and/or "move to bottom" capability that only someone logged in as admin would have.  This would provide the ultimate flexibility in organizing forums that are read-only, for example.