I have the following query

SELECT * from PHOTOS WHERE Subject = '$Subject' AND Location = '$Location' ORDER BY Number

It results in the following output

1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9

How does PHP/MySql think 10 is lower than 2??

This is driving me nuts, any help would be greatly appreciated.

6 Years
Discussion Span
Last Post by jenmay92683

My guess is you defined your Number field/column as Text data time instead of INT. So it is doing ascii comparisons. In the ascii table the '1' comes before the '2'. You need to change the data type of the column to INT or cast the Number:
http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html SELECT * from PHOTOS WHERE `Subject`= '$Subject' AND `Location` = '$Location' ORDER BY CONVERT(`Number`,UNSIGNED INTEGER)


Am I the only one that gets so wrapped up in the bigger issues that you forget to check the small details?

I had my boyfriend helping me set up the tables and I didn't even think to check if he followed my notes correctly.

Thanks so much, hielo...sorry for the silly question.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.