hostfreak Posted August 2, 2006 Share Posted August 2, 2006 Thought I started another thread about this, but can't seem to find it anywhere. Anyways I have a mysql field set as an INT. It holds numbers. Then I have a page that lists the numbers in order. Well it comes up that I need that page to hold letters as well. So I changed it to a VARCHAR but then it doesn't list it right on the page (which is by the field ASC). So I am wondering how can I make the field a combination of numbers/letters and have it list in order? Link to comment https://forums.phpfreaks.com/topic/16277-mysqlphp-question/ Share on other sites More sharing options...
hitman6003 Posted August 2, 2006 Share Posted August 2, 2006 Cast the field to int would be my recommendation. I haven't done it before, but it should work.[code]SELECT field FROM table ORDER BY CAST(field AS INT) ASC[/code]http://dev.mysql.com/doc/refman/5.1/en/cast-functions.htmlHere's a google result that you may want to try:http://blog.feedmarker.com/2006/02/01/how-to-do-natural-alpha-numeric-sort-in-mysql/ Link to comment https://forums.phpfreaks.com/topic/16277-mysqlphp-question/#findComment-67508 Share on other sites More sharing options...
hostfreak Posted August 2, 2006 Author Share Posted August 2, 2006 Neither one worked. I dont think the cast function allows for it to be casted as an INT, atleast thats what I am assuming after reading the page for it. Second one just doesn't list them right. Link to comment https://forums.phpfreaks.com/topic/16277-mysqlphp-question/#findComment-67546 Share on other sites More sharing options...
hostfreak Posted August 2, 2006 Author Share Posted August 2, 2006 Anyone else know of a way to do this? Link to comment https://forums.phpfreaks.com/topic/16277-mysqlphp-question/#findComment-67756 Share on other sites More sharing options...
AndyB Posted August 2, 2006 Share Posted August 2, 2006 SELECT whatever FROM your_table ORDER BY names + 0 ASCCan you explain what you meant by "didn't list them right". Link to comment https://forums.phpfreaks.com/topic/16277-mysqlphp-question/#findComment-67757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.