use 2 order by For List Data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sina_nop
Forum Newbie
Posts: 5
Joined: Wed Aug 26, 2009 5:17 am

use 2 order by For List Data

Post by sina_nop »

I want use 2 order by in mysql query , and every thing in ok :

Code: Select all

 
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)
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: use 2 order by For List Data

Post by jayshields »

Use a WHERE clause to specify only levels equal to or above 2 to be returned in the dataset?
sina_nop
Forum Newbie
Posts: 5
Joined: Wed Aug 26, 2009 5:17 am

Re: use 2 order by For List Data

Post by sina_nop »

Thanks
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]
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: use 2 order by For List Data

Post by jayshields »

Re-number your permission levels.
sina_nop
Forum Newbie
Posts: 5
Joined: Wed Aug 26, 2009 5:17 am

Re: use 2 order by For List Data

Post by sina_nop »

My Query :

Code: Select all

 
    $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");
 
 
sina_nop
Forum Newbie
Posts: 5
Joined: Wed Aug 26, 2009 5:17 am

Re: use 2 order by For List Data

Post by sina_nop »

Re-number your permission levels.
Thanks , but in too many file i used this levels
there is no condition for my query?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: use 2 order by For List Data

Post by jayshields »

From what I gather, you want to order your data, and you want to order it neither in ascending or descending order. So you need to either change the indexes on which you are ordering or create a new index to order on, from which you would be able to order ascending or descending.
Post Reply