Jump to content

Ordering topics


3raser

Recommended Posts

Hi there! I'm still getting use to using multiple rows when ordering in SQL, but I have a question. How can I display topics that are stickied first, then display all the threads below ordered by lastpost?

 

I tried:

 

//thread details
$query = mysql_query("SELECT `date`,`lock`,`sticky`,`status`,`title`,`username`,`id`,`lastposter`,`lastpost` FROM threads WHERE parent = '{$_GET['forum']}' ORDER BY lastpost, sticky DESC LIMIT $start,$per_page") or die(mysql_error());

 

And the stickies do show up first, but all the regular threads aren't showing ordered by laspost DESC. Why is that? :/

 

Lastpost = datetime

Link to comment
https://forums.phpfreaks.com/topic/257261-ordering-topics/
Share on other sites

Order by your sticky column first.  I assume this is just a 1/0 tinyint column.  To get the sticky ones first you'd order them descending.

 

After that you order by the lastpost column in descending order.  That will make it so that you should get the newest posts at the top, even within the group of sticky posts.

 

Each column in the order by clause needs to have it's order specified.  if none is specified it defaults to ascending so you'd want:

ORDER BY 
     sticky DESC
     , lastpost DESC

 

Link to comment
https://forums.phpfreaks.com/topic/257261-ordering-topics/#findComment-1318686
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.