soycharliente Posted August 24, 2007 Share Posted August 24, 2007 I tried searching Google for some stuff about sorting table results. I want to be able to click the different headers and sort the results by each field. Anyone know some good sites/tutorials? Quote Link to comment https://forums.phpfreaks.com/topic/66561-solved-sorting-table-results/ Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 Assuming you are using MySQL, here is the documentation for it. http://dev.mysql.com/doc/refman/5.1/en/order-by-optimization.html Quote Link to comment https://forums.phpfreaks.com/topic/66561-solved-sorting-table-results/#findComment-333387 Share on other sites More sharing options...
soycharliente Posted August 24, 2007 Author Share Posted August 24, 2007 I was looking more for how to set up the links/code so that it will sort ASC each field when you click on it (and DESC if clicked again). Quote Link to comment https://forums.phpfreaks.com/topic/66561-solved-sorting-table-results/#findComment-333421 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 That is a little bit trickier. I don't have my code here, but the way I did it (if I remember correctly) was with a GET variable that told whether it was asc or desc. To dynamically change the query, all you have to do is something like this: $query = "SELECT * FROM table"; if ($_GET['var'] == "asc") $query .= " ORDER BY DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/66561-solved-sorting-table-results/#findComment-333427 Share on other sites More sharing options...
soycharliente Posted August 26, 2007 Author Share Posted August 26, 2007 And should I just assume that the user won't mess with what the URL is and not care about people typing in random smut in the URL? Quote Link to comment https://forums.phpfreaks.com/topic/66561-solved-sorting-table-results/#findComment-334720 Share on other sites More sharing options...
dbo Posted August 26, 2007 Share Posted August 26, 2007 Of course not. It was an example. Quote Link to comment https://forums.phpfreaks.com/topic/66561-solved-sorting-table-results/#findComment-334726 Share on other sites More sharing options...
lemmin Posted August 27, 2007 Share Posted August 27, 2007 With my code I posted, nothing malicious could be done with typing anything into the URL. It simply checks if the var IS asc, it doesn't use that value in the query. Quote Link to comment https://forums.phpfreaks.com/topic/66561-solved-sorting-table-results/#findComment-335297 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.