Jump to content


Photo

mysql/php question


  • Please log in to reply
4 replies to this topic

#1 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 02 August 2006 - 01:41 AM

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?

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 02 August 2006 - 01:45 AM

Cast the field to int would be my recommendation.  I haven't done it before, but it should work.

SELECT field FROM table ORDER BY CAST(field AS INT) ASC

http://dev.mysql.com...-functions.html

Here's a google result that you may want to try:

http://blog.feedmark...-sort-in-mysql/

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 02 August 2006 - 02:46 AM

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.

#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 02 August 2006 - 11:21 AM

Anyone else know of a way to do this?

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 02 August 2006 - 11:30 AM

SELECT whatever FROM your_table ORDER BY names + 0 ASC

Can you explain what you meant by "didn't list them right".
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users