I am trying to get listings to sort in ascending order according to a number field but the results are shown in a wacky order like 103, 113, 17, 202 ... This is what I used: $result = mysql_query("SELECT * From name-of-table where xxxx='parameter1'and xxxx='parameter2' ORDER BY name-of-field"); Would someone be kind enough to set me straight here please?
flakas123, I appreciate you trying to help but that doesn't solve my problem. It is not that the order is going in the wrong direction but that the order is not running sequentially. Now, using the ASC it runs 17, 202, 22, 24, 24, 24, 25, 32... It should be 17, 22, 24, 24, 24, 25 ... Any more ideas?
Google is my friend. Found the answer. Just in case anyone is interested or has the same problem - add +0 to the field name and it converts the field from a character into an integer. http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html
The piece you posted is absolutely correct. You might be doing something wrong when you replace the placeholders with the actual values - we need to see the actual code in order to help you.
Thank you for sharing that link. You said on your first post "a number field" and the comment on that page from the MySQL 5.0 docs shows us how to order strings as numbers. So I assume you are using a string field (maybe a varchar) for storing numbers. Am I right? Cheers
Yes, you are correct, Nabil. And as you may have guessed I am not the sharpest tool in the shed when it comes to things related to dbases.