Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

mysql ORDER BY

Recommended Posts

Hi,
I'm not sure if this is right so i tohught i'd get some advice from it. I want to search my members databse and list them in a table, Which has been done. But i want to list them in a particular order. I want to order them like:
rank(admin, super-mod, mod) and then the members by usernames [b]ASC[/b]ending.

is this right:
$sql = mysql_query("SELECT user,rank,rep,mem_mail FROM accounts ORDER BY rank(admin,super-mod,mod),user ASC");

Share this post


Link to post
Share on other sites
you can run the query and try it out. don't worry this query does not mess up your database.

Share this post


Link to post
Share on other sites
If that fails you can try
[code]
SELECT user,rank,rep,mem_mail,
CASE WHEN rank='admin' THEN 1 WHEN rank='super-mod' THEN 2 ELSE 3 END as ranksort
FROM accounts
ORDER BY ranksort,user");[/code]

Share this post


Link to post
Share on other sites
alright :] thanks...

Share this post


Link to post
Share on other sites

×

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.