Jump to content


Photo

mysql ORDER BY


  • Please log in to reply
3 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 15 July 2006 - 01:01 PM

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 ASCending.

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

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 15 July 2006 - 01:50 PM

you can run the query and try it out. don't worry this query does not mess up your database.
Life's too short for arguing.

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 15 July 2006 - 03:10 PM

If that fails you can try
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");

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 15 July 2006 - 05:21 PM

alright :] thanks...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users