The title pretty much states my question: Is there a way in PHP to force the row of my choosing to appear first in a mysql query result set? For example, I will query the db to select the names of football players and I always want "Bo Jackson" to appear first (just to remind everyone of his unmatched awesomeness). Thanks. -chris
Well.. you could do this in in your SQL query... something like:
(SELECT `name`, `whatever` FROM `mytable` WHERE `name` = 'Bo Jackson') UNION (SELECT `name`, `whatever` FROM `mytable` WHERE `name` != 'Bo Jackson')
I agree that you should do it in the SQL query. But I have another way of doing it:
SELECT whatever FROM table WHERE whatever ORDER BY CASE name WHEN 'Bo Jackson' THEN 1 ELSE 999 END
And that's why I shouldn't be posting in the database forum! :o
Lol, learned that from LarsBerg in this forum, otherwise I would not have a clue.
Edit: Nice that it is not you that are correcting me, must be the first time. :p