'Order by' question
| From: | Justin dot Baiocchi at csiro dot au | Date: | Thu, 10 Feb 2005 02:38:23 +0000 |
| Subject: | 'Order by' question | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-38537@lists.php.net to get a copy of this message | ||
Hi,
I have a MySQL varchar column which I wish to display. Most of the
entries are numbers eg 1, 2, 3 etc etc. But some are numbers and letters
eg 34A, 34B, 35A.
When I display the column I am able to sort by number using the "order
by column_name+0" command, as in:
$result = mysql_query("SELECT id, house, pen, date_format(start,'%M %D,
%Y') as start, date_format(end,'%M %D, %Y') as end, details FROM
animalhouse WHERE house='old' ORDER BY pen+0") or die (mysql_error());
However, it doesn't sort the letters properly, so I get 34B, 34A, 34C
etc etc.
Is there a simple way for me to make it sort by number first and then by
letter?
Thanks
Justin