princeofpersia Posted February 21, 2012 Share Posted February 21, 2012 Hi Guys I have a product page in mysql as below: id itemnumber order_id 1 348939012 2 2 535432454 1 3 543253424 4 4 987698769 3 I need to order this in my PHP mysql_fetch_assoc by order id. What I mean is I need to list them by order_id: 1,2,3,4 I have used ORDER BY order_id but still it wont work, any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/257455-order-database-results-in-php/ Share on other sites More sharing options...
El Chupacodra Posted February 21, 2012 Share Posted February 21, 2012 How did you write the sort when it didn't work? It's a pretty failsafe command when used right. Quote Link to comment https://forums.phpfreaks.com/topic/257455-order-database-results-in-php/#findComment-1319500 Share on other sites More sharing options...
princeofpersia Posted February 21, 2012 Author Share Posted February 21, 2012 $select=mysql_query("SELECT * FROM products ORDER BY order_id"); and then while($row=mysql_fetch_assoc($select)) {} Quote Link to comment https://forums.phpfreaks.com/topic/257455-order-database-results-in-php/#findComment-1319503 Share on other sites More sharing options...
trq Posted February 21, 2012 Share Posted February 21, 2012 It should work fineWhat results are you getting? What data type is order_id? Quote Link to comment https://forums.phpfreaks.com/topic/257455-order-database-results-in-php/#findComment-1319504 Share on other sites More sharing options...
princeofpersia Posted February 21, 2012 Author Share Posted February 21, 2012 It just doesn't the same code works on another website, I check mysql versions, they are same. It is a varchar Quote Link to comment https://forums.phpfreaks.com/topic/257455-order-database-results-in-php/#findComment-1319505 Share on other sites More sharing options...
trq Posted February 21, 2012 Share Posted February 21, 2012 Why are you storing integers in a varchar type? That is your issue. Quote Link to comment https://forums.phpfreaks.com/topic/257455-order-database-results-in-php/#findComment-1319507 Share on other sites More sharing options...
princeofpersia Posted February 21, 2012 Author Share Posted February 21, 2012 I just changed it to int but still messed up Quote Link to comment https://forums.phpfreaks.com/topic/257455-order-database-results-in-php/#findComment-1319509 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.