I have a local-only project which I'm working on where I have a table with id, title and price fields.
Example info:
ID || Title || Price
1 - Title 1 - 8.00
2 - Title 2 - 75.00
3 - Title 3 - 70.00
When I try to ORDER BY price it comes back like this:
8.00
75.00
70.00
Statement:
$query = mysql_query("Select * From table ORDER BY price DESC");
What am I doing wrong?
Your price column must have a character CHAR() or VARCHAR() type rather than a numeric type. Cast it as a DECIMAL in the ORDER BY:
Select * From table ORDER BY CAST(price AS DECIMAL(10,2)) DESC
The real fix for this would be to change the price data type to a proper numeric type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With