DarkHorizon Posted June 22, 2006 Share Posted June 22, 2006 I have a database containing products, each has a price.i want to be able to sort the database by price, high to low or low to high.$query = "SELECT * FROM $table order by price asc LIMIT $limitvalue, $limit"; $limitvalue and $limit are pagination variables which work okaythe table gets sorted by price okay but i get:1.5017.0019.502.0022.00234.003.19you can see whats happening, wbut why? and how can i fix it display the correct ascending order. Quote Link to comment https://forums.phpfreaks.com/topic/12637-trouble-sorting-numbers-in-a-mysql-database-resolved/ Share on other sites More sharing options...
AndyB Posted June 22, 2006 Share Posted June 22, 2006 Why does it sort like that? Because you are storing the prices as strings not numbers and that sort is correct for strings. Change your field type to something like FLOAT(6,2) instead of VARCHAR or whatever you're using. Quote Link to comment https://forums.phpfreaks.com/topic/12637-trouble-sorting-numbers-in-a-mysql-database-resolved/#findComment-48467 Share on other sites More sharing options...
DarkHorizon Posted June 22, 2006 Author Share Posted June 22, 2006 blimey, simple as that eh?i've been waving my fist at the computer Basil Fawlty style...and swearing..well, its a good job you is a moderators and i aint.cheers buddy.edit: Just tried it, it worked....prob resolved! Quote Link to comment https://forums.phpfreaks.com/topic/12637-trouble-sorting-numbers-in-a-mysql-database-resolved/#findComment-48492 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.