sina_nop Posted August 26, 2009 Share Posted August 26, 2009 I want use 2 order by in mysql query , and every thing in ok : ORDER by level DESC , id ASC my problem with level filed cause : in result list I want Level = 2 is first and after it Level 3 but when I using level DESC show first level 3 if I use level ASC my list start from normal user! and level 1 (end to first) Quote Link to comment https://forums.phpfreaks.com/topic/171928-use-2-order-by-for-list-data/ Share on other sites More sharing options...
kickstart Posted August 26, 2009 Share Posted August 26, 2009 Hi Sounds like you just want to exclude those with a level of 1. So:- WHERE level > 1 ORDER BY level ASC, id ASC All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/171928-use-2-order-by-for-list-data/#findComment-906559 Share on other sites More sharing options...
sina_nop Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks keith better I explain user level i want sort online user and i used one WHERE guest = '0' (just reg users) there is 3 Level : level 2 : God Admin level 3 : moderator level 1 : normal user I want sort users online : First : God Admin [level 2] Two : moderator [level 3] Tree : normal user [level 1] Quote Link to comment https://forums.phpfreaks.com/topic/171928-use-2-order-by-for-list-data/#findComment-906576 Share on other sites More sharing options...
sina_nop Posted August 26, 2009 Author Share Posted August 26, 2009 My Query : $ListOnline = $db->sql_query("SELECT w.uname, w.module, w.url, u.user_id, u.user_level, u.user_allow_viewonline FROM Table_session AS w LEFT JOIN Table_users AS u ON u.username = w.uname WHERE guest = '0' ORDER by user_level DESC, user_id ASC"); Quote Link to comment https://forums.phpfreaks.com/topic/171928-use-2-order-by-for-list-data/#findComment-906580 Share on other sites More sharing options...
kickstart Posted August 26, 2009 Share Posted August 26, 2009 Hi Can think of 2 options. Either use a case statement to determine a sort order based on the user level. Or hold a sort order on the table listing levels and do a join to retrieve this. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/171928-use-2-order-by-for-list-data/#findComment-906614 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.