lalnfl Posted April 23, 2011 Share Posted April 23, 2011 Lets say I have this query: $sql = mysql_query("SELECT * FROM Member ORDER BY posts DESC LIMIT 10"); while ($get = mysql_fetch_array($sql)){ $row .= $get['id']; $posts .= $get['posts']; echo "$row - $posts<br />"; } Lets say I have two of rows, with posts fields of 84 and 803. When it displays it, it grabs the 84 row first, when I want the bigger number 803 first. Is there a way to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/234521-mysql-order-by/ Share on other sites More sharing options...
fugix Posted April 23, 2011 Share Posted April 23, 2011 so instead of it descending it actually ascends? Quote Link to comment https://forums.phpfreaks.com/topic/234521-mysql-order-by/#findComment-1205246 Share on other sites More sharing options...
lalnfl Posted April 23, 2011 Author Share Posted April 23, 2011 I have tried it with more numbers, and it seems to be doing something like this: 84 803 77 707 51 505 It doesn't take into account the third number on some of these. Quote Link to comment https://forums.phpfreaks.com/topic/234521-mysql-order-by/#findComment-1205252 Share on other sites More sharing options...
wildteen88 Posted April 23, 2011 Share Posted April 23, 2011 What data type have you set your id field to when creating your table? Make sure the id column is set to INT Quote Link to comment https://forums.phpfreaks.com/topic/234521-mysql-order-by/#findComment-1205256 Share on other sites More sharing options...
lalnfl Posted April 23, 2011 Author Share Posted April 23, 2011 The id is INT, but should the posts be INT aswell? Right now it is VARCHAR. Quote Link to comment https://forums.phpfreaks.com/topic/234521-mysql-order-by/#findComment-1205258 Share on other sites More sharing options...
fugix Posted April 23, 2011 Share Posted April 23, 2011 yes it needs to be int unless you are planning on inserting letters. Quote Link to comment https://forums.phpfreaks.com/topic/234521-mysql-order-by/#findComment-1205260 Share on other sites More sharing options...
Pikachu2000 Posted April 23, 2011 Share Posted April 23, 2011 VARCHAR() fields will order alphabetically, which it is doing now. That order is correct for a DESC order on a VARCHAR field. Quote Link to comment https://forums.phpfreaks.com/topic/234521-mysql-order-by/#findComment-1205261 Share on other sites More sharing options...
lalnfl Posted April 23, 2011 Author Share Posted April 23, 2011 Alrighty guys thanks! Wasn't too sure about this. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/234521-mysql-order-by/#findComment-1205264 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.