Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORDER BY

Status
Not open for further replies.

7724

Programmer
Feb 25, 2005
28
GB
Writing a php script, which looks into a MySQL database.

Now I want the script to look into what data has been saved into my game table and output the data by positions in order iw goalkeeper 1st, defender 2nd, midfield 3rd. I thought it would be like this but it does not work - any idea thanks?


Code:
$Query = "SELECT * from $TableName ORDER by (game.profile = 'Goalkeeper', game.profile = 'defender', game.profile = 'Midfield',)";
 
this won't work unless $TableName eq "game". You are not selecting the game Table, so MySQL won't know where you are getting the variables from. Also, ORDER BY expects a list of columns to group by. You are giving it...well I am not sure what you are giving it :). Tell us what it is you want to do, and describe $TableName table
 
Code:
order by case game.profile 
 when 'Goalkeeper' then 1
 when 'defender' then 2
 when 'Midfield' then 3 end

Actually

Code:
$Query = "SELECT * from $TableName ORDER by (game.profile = 'Goalkeeper', game.profile = 'defender', game.profile = 'Midfield') desc";

should work if Mysql have implemented row expressions correctly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top