3raser Posted February 18, 2012 Share Posted February 18, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257261-ordering-topics/ Share on other sites More sharing options...
kicken Posted February 18, 2012 Share Posted February 18, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257261-ordering-topics/#findComment-1318686 Share on other sites More sharing options...
3raser Posted February 18, 2012 Author Share Posted February 18, 2012 Thank you kicken! I really appreciate the help. Gaining more knowledge of SQL is fun. ^.^ Quote Link to comment https://forums.phpfreaks.com/topic/257261-ordering-topics/#findComment-1318696 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.