Jump to content

Archived

This topic is now archived and is closed to further replies.

hostfreak

mysql/php question

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.html

Here'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/

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
SELECT whatever FROM your_table ORDER BY names + 0 ASC

Can you explain what you meant by "didn't list them right".

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.