Forum Moderators: coopster

Message Too Old, No Replies

Problem Sorting By Price

mysql sort price php problem

         

matthewamzn

12:00 am on Aug 10, 2005 (gmt 0)

10+ Year Member



I have a mysql database and I'm using php to display the results in a table on my website. I currently have it set so the results are sorted by the price field. But it doesn't seem to sort it by the value of the products. For example some of the results on my page give:
$14.95
$19.99
$24.98
$32.95
$8.85
$9.71

The price field is set to varchar(255). I'm thinking maybe I should change the type of field, but I'm not sure to what.

matthewamzn

1:17 am on Aug 10, 2005 (gmt 0)

10+ Year Member



nevermind, i had to choose a better field type

yktan

2:17 am on Aug 10, 2005 (gmt 0)

10+ Year Member



Yeap, in your case it's better to define it as a numeric field

coopster

12:21 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I agree, and MySQL itself recommends type DECIMAL. A related discusssion:

SQL problem - 'order by' with numbers [webmasterworld.com]