[SOLVED] ORDER by ASC not working!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
paladaxar
Forum Commoner
Posts: 85
Joined: Fri Jun 18, 2004 11:50 pm

ORDER by ASC not working!

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
paladaxar
Forum Commoner
Posts: 85
Joined: Fri Jun 18, 2004 11:50 pm

Post by paladaxar »

Dude...you're awesome! Problem solved! Thank you!
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Post 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);
Post Reply