kts Posted February 23, 2009 Share Posted February 23, 2009 Hey everyone, thanks for reading. I have done this before but many moons ago. I am trying to have a few drops downs that will change the Order By clause on a Select statement. From my memory I remember you need to have the order by in a variable with a case statement to control which one it will become. I am having some trouble doing so if anyone has some sample code that they use to do this I would greatly appreciate it. I'm not sure as to why I am not able to re-create it right now, but I do not use case statements very much. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/146447-trying-to-sort-a-select-statement/ Share on other sites More sharing options...
genericnumber1 Posted February 23, 2009 Share Posted February 23, 2009 Can you show us what you're trying? Link to comment https://forums.phpfreaks.com/topic/146447-trying-to-sort-a-select-statement/#findComment-768918 Share on other sites More sharing options...
jon23d Posted February 23, 2009 Share Posted February 23, 2009 How about this: // set the allowed sort fields $allowed_sorts = array("name", "date", "amount"); // use the specified sort, or a default $sort = ($_GET['sort'], $allowed_sorts) ? $_GET['sort'] : 'name'; // now execute the query and continue $rs = mysql_query("SELECT * FROM table ORDER BY $sort ASC;"); Link to comment https://forums.phpfreaks.com/topic/146447-trying-to-sort-a-select-statement/#findComment-768967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.