Jump to content

Small issue with sorting query results.


Solarpitch

Recommended Posts

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));

 

Link to comment
https://forums.phpfreaks.com/topic/69395-small-issue-with-sorting-query-results/
Share on other sites

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.