Sort by replies

  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Could it be possible to get a sorting feature that would sort by number of replies, then by date

something like the following:
The $sql line here starts on line 314 of viewtopic.php of my phpBB install (which may be rather old).
PHP Code: [ Select ]
<?php
 
// some numeric symbol for sort order, 0 is default
 
$topics_sort_order = intval($_GET['sort']);
 
if( $topics_sort_order == 1 ){
 
   $topics_order_by = 't.topic_type DESC, t.topic_replies ASC, t.topic_last_post_id DESC';
 
} else {
 
   $topics_order_by = 't.topic_type DESC, t.topic_last_post_id DESC';
 
}
 
 
 
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
 
   FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
 
   WHERE t.forum_id = $forum_id
 
      AND t.topic_poster = u.user_id
 
      AND p.post_id = t.topic_first_post_id
 
      AND p2.post_id = t.topic_last_post_id
 
      AND u2.user_id = p2.poster_id
 
      AND t.topic_type <> " . POST_ANNOUNCE . "
 
      $limit_topics_time
 
   ORDER BY $topics_order_by
 
   LIMIT $start, ".$board_config['topics_per_page'];
 
?>
  1. <?php
  2.  
  3. // some numeric symbol for sort order, 0 is default
  4.  
  5. $topics_sort_order = intval($_GET['sort']);
  6.  
  7. if( $topics_sort_order == 1 ){
  8.  
  9.    $topics_order_by = 't.topic_type DESC, t.topic_replies ASC, t.topic_last_post_id DESC';
  10.  
  11. } else {
  12.  
  13.    $topics_order_by = 't.topic_type DESC, t.topic_last_post_id DESC';
  14.  
  15. }
  16.  
  17.  
  18.  
  19. $sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
  20.  
  21.    FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
  22.  
  23.    WHERE t.forum_id = $forum_id
  24.  
  25.       AND t.topic_poster = u.user_id
  26.  
  27.       AND p.post_id = t.topic_first_post_id
  28.  
  29.       AND p2.post_id = t.topic_last_post_id
  30.  
  31.       AND u2.user_id = p2.poster_id
  32.  
  33.       AND t.topic_type <> " . POST_ANNOUNCE . "
  34.  
  35.       $limit_topics_time
  36.  
  37.    ORDER BY $topics_order_by
  38.  
  39.    LIMIT $start, ".$board_config['topics_per_page'];
  40.  
  41. ?>

That's just a guess, I haven't actually tried it, but you get the idea. Set a link somewhere for $sort and it's done. I'll try it on semitekie.com later and see what happens.

Anyway, just a suggestion.

Thanks

*edit
I've checked it out and that code works beautifully
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

OK, I'll just play dumb and ask the obvious question -- why would you want/need that type of sort? I most likely browse the forums different than most. I just read almost everything that comes along. So in truth I don't understand the reason.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Well, I like to hit the posts that don't have any replies first, no matter when they were made. Often these are questions that are simply so complex that nobody knows the answer.

I mean, yeah, I scan through all the forums too, but this is what I look for first, so I just thought it'd be nice if there were a way to sort by that. This would certainly not be default though, the code I posted above sorts the same way it does now by default, it's only when you add "&sort=1" to the query string that it sorts by number of replies first.

As I said, it's just a suggestion and it's not like I'm going to stop coming to the site or anything if it doesn't get implemented. Nor is it that it's all that hard to scan through the topics to find those with little or no replies. It's just something that would make it easier on me and others who scan the forums in this way.

I admit, it's a rather odd request, just figured I'd ask. I suppose you could use this to build a framework for other types of sorting, but to be honest, I couldn't think of any that people would actually use, except maybe reverse sorting (changing the DESCs to ASCs and vice versa). It could probably also be done in a cleaner method (I don't like accessing environment variables halfway through a script myself), but the code above iterates exactly what I was suggesting in a fairly plain manner.

ATNO/TW wrote:
I just read almost everything that comes along.

Yeah, I don't know how you do that. That's why you have "Super" in your title ;)
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

Just curious this213, have you ever seen this link?
http://www.ozzu.com/search.php?search_id=unanswered

It's the view unanswered posts link under the Posting Information header in the nav menu. Not quite exactly what you want, but I think it's close enough.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

yeah, Ive seen it. It's just that it's not topic specific.

As I said, it's not really that big of a deal to me. If it can't be implemented for whatever reason, that's fine by me.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

Now that I understand your reasoning, I can see how it would be beneficial. Guess we'll have to see if Bigweb is interested.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 1 guest
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.