prw Posted April 3, 2011 Share Posted April 3, 2011 I wish to order my results by its occurrence inside the $status array. Basically all of the results with the status 'New' are to be listed first, then the results with the status Today, Tomorrow, Soon and so on. Is this possible, or is there alternatively a different approach to ordering my results how I desire? $status = array('New', 'Today', 'Tomorrow', 'Soon', 'Future', 'Complete'); $display->get_results("SELECT * FROM todo ORDER by status DESC"); Link to comment https://forums.phpfreaks.com/topic/232531-order-results-by-its-occurrence-inside-an-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 3, 2011 Share Posted April 3, 2011 You would use ORDER BY FIELD(....) - http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field ORDER BY FIELD(status, 'New', 'Today', 'Tomorrow', 'Soon', 'Future', 'Complete') Link to comment https://forums.phpfreaks.com/topic/232531-order-results-by-its-occurrence-inside-an-array/#findComment-1196095 Share on other sites More sharing options...
Zane Posted April 3, 2011 Share Posted April 3, 2011 you could give them a numerical value instead. Otherwise, they'll just be ordered alphabetically. Link to comment https://forums.phpfreaks.com/topic/232531-order-results-by-its-occurrence-inside-an-array/#findComment-1196096 Share on other sites More sharing options...
prw Posted April 3, 2011 Author Share Posted April 3, 2011 That works PFMaBiSmAd, thanks! Link to comment https://forums.phpfreaks.com/topic/232531-order-results-by-its-occurrence-inside-an-array/#findComment-1196098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.