Solarpitch Posted September 14, 2007 Share Posted September 14, 2007 In the below code I am simply trying to sort a list of results in the category "Drivers" by price. I can achieve this fine but it only seems to take the first 2 digits of the price when sorting, so... Instead of sorting like: €38 €70 €125 €175 €250 €370 Its sorts like: €125 €175 €250 €370 €38 €70 $limit = 'LIMIT ' .($pageno - 1) * $max .',' .$max; $query = "SELECT * FROM ads WHERE category = 'Drivers' AND validation = 0 ORDER BY '$price' $limit"; $result = mysqli_query($mysql_connect, $query) or die (mysqli_error($mysql_connect)); Quote Link to comment https://forums.phpfreaks.com/topic/69395-small-issue-with-sorting-query-results/ Share on other sites More sharing options...
redking Posted September 14, 2007 Share Posted September 14, 2007 $query = "SELECT * FROM ads WHERE category = 'Drivers' AND validation = 0 ORDER BY '$price' $limit"; should be $query = "SELECT * FROM ads WHERE category = 'Drivers' AND validation = 0 ORDER BY price DESC $limit"; where price is the name of your price field in the database DESC = descending order ASC = Ascending order Quote Link to comment https://forums.phpfreaks.com/topic/69395-small-issue-with-sorting-query-results/#findComment-348674 Share on other sites More sharing options...
Solarpitch Posted September 14, 2007 Author Share Posted September 14, 2007 No, still hasnt resolved the issue. :-\ Its really strange, I dont think theres anything wrong with the query itself. Quote Link to comment https://forums.phpfreaks.com/topic/69395-small-issue-with-sorting-query-results/#findComment-348677 Share on other sites More sharing options...
zampu Posted September 14, 2007 Share Posted September 14, 2007 $query = "SELECT * FROM ads WHERE category = 'Drivers' AND validation = 0 ORDER BY price DESC 10, 0"; or $query = "SELECT * FROM ads WHERE category = 'Drivers' AND validation = 0 ORDER BY price DESC 0, 10"; Quote Link to comment https://forums.phpfreaks.com/topic/69395-small-issue-with-sorting-query-results/#findComment-348704 Share on other sites More sharing options...
BlueSkyIS Posted September 14, 2007 Share Posted September 14, 2007 it looks like you're storing the prices as strings, including the Euro symbol. the database is sorting the strings in proper order. don't store numbers as strings. Quote Link to comment https://forums.phpfreaks.com/topic/69395-small-issue-with-sorting-query-results/#findComment-348732 Share on other sites More sharing options...
syntaxerror Posted September 15, 2007 Share Posted September 15, 2007 i believe php has specific sorting functions for in a 'human' sense natsort() i think it might come in handy Quote Link to comment https://forums.phpfreaks.com/topic/69395-small-issue-with-sorting-query-results/#findComment-348801 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.