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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.