doddsey_65 Posted November 17, 2010 Share Posted November 17, 2010 I am creating a sticky topic feature for my forum and dont know how to keep all topics marked sticky at the top of the list generated by the while loop. Any one have any ideas? They are ordered by the post date column. Here is the query: $posts_info_query = $db->query("SELECT p.post_id, p.topic_id, p.forum_id, p.post_poster, p.post_subject, p.post_content, p.post_time, p.post_edit_by, p.post_edit_date, p.post_edit_num, p.post_approved, p.post_quoting, m.user_id, m.user_username, m.user_group, m.user_regdate, m.user_birthday, m.user_online, m.user_sex, m.user_location, m.user_show_sex, m.user_show_location, m.user_show_status, m.user_avatar, m.user_sig, m.user_posts FROM ".DB_PREFIX."posts as p LEFT JOIN ".DB_PREFIX."members as m ON p.post_poster = m.user_username WHERE p.topic_id = '$topic_id' ORDER BY p.post_time ASC LIMIT $start, $limit") or trigger_error("SQL", E_USER_ERROR); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/218934-keep-1-record-at-top-in-while-loop/ Share on other sites More sharing options...
joel24 Posted November 17, 2010 Share Posted November 17, 2010 have a column 'sticky', with 1 (on) or 0 (off) values. then have your order like so ORDER BY sticky DESC, p.post_time ASC *edit* make sure the default value for the column is 0 Quote Link to comment https://forums.phpfreaks.com/topic/218934-keep-1-record-at-top-in-while-loop/#findComment-1135399 Share on other sites More sharing options...
doddsey_65 Posted November 17, 2010 Author Share Posted November 17, 2010 thanks, i already have the column but didnt know you could order by 2 columns. Sorry I also just noticed that i provided the wrong query lol. Quote Link to comment https://forums.phpfreaks.com/topic/218934-keep-1-record-at-top-in-while-loop/#findComment-1135400 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.