searls03 Posted September 3, 2013 Share Posted September 3, 2013 hi all. I am looking for a way to order a php query result by a specific value, not like an id ASC, but like first column 1=red(there could be multiples, so all that have column 1 as red display first), then column2=blue. I have been looking all day and havent been able to find anything. any help? Quote Link to comment Share on other sites More sharing options...
objnoob Posted September 3, 2013 Share Posted September 3, 2013 http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field the MySQL FIELD() function is great for this. SELECT rating FROM tRatings ORDER BY FIELD(rating, 'Professional', 'Advanced', 'Amateur'); Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 3, 2013 Share Posted September 3, 2013 (edited) I'm not sure I really understand the question. But, I think you want to sort such that all records where column 1 = red sort first, then by column 2 = blue, etc. If so, the solution is simple, you can create your sorting conditions as comparisons SELECT * FROM table_name ORDER BY column_1 = 'red', column_2='blue' EDIT: Why is this in the PHP forum? You should know better after 900 posts. Moving to MySQL forum. Edited September 3, 2013 by Psycho Quote Link to comment 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.