Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.