Page 1 of 1

ORDER by ASC not working!

Posted: Sun Aug 01, 2004 6:46 pm
by paladaxar
I'm a beginner in the world of databases but I did have enough sense to consult the MySql Manual before asking this simple question. No help there.

Here's my problem: I am trying to sort a column that contains the days of a month. When I sort the column (order by day asc) it puts a day of (for example) 2 AFTER a day like 19.

Here's my question: Is there any way that I can query the database and let it know that even though there is no leading zero before the 2, it is still lower than 19?

Thanx.

Posted: Sun Aug 01, 2004 6:55 pm
by feyd
I'd reason to guess the column type is not a numeric type. That's the reason for it not ordering correctly. If you switched it to TINYINT or any of the other INT variants, it should work..

Posted: Sun Aug 01, 2004 7:04 pm
by paladaxar
Dude...you're awesome! Problem solved! Thank you!

Posted: Sun Aug 01, 2004 7:12 pm
by xjake88x
If you're ordering by months and they're text, you can do this:

Code: Select all

$sql = mysql_query("select * from my_table order by ".
"month='January' ASC, " .
"month='February' ASC, " .
"month='March' ASC, " .
"month='April' ASC, " .
"month='May' ASC, " .
"month='June' ASC, " .
"month='July' ASC, " .
"month='August' ASC, " .
"month='September' ASC, " .
"month='October' ASC, " .
"month='November' ASC, " .
"month='December' ASC") or die ("Query failed.");

mysql_query($sql);