Jump to content

mysql/php question


hostfreak

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?
Link to comment
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/
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.