Jump to content


Photo

Human readable alphanum.


  • Please log in to reply
5 replies to this topic

#1 PureEvil

PureEvil
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 September 2005 - 07:06 PM

Trying to pull a ton of data from a database that I would like ordered by a number that has been assigned to that data by the end user. IE 1,2,3,4,5,6

I'm using mysql_query("SELECT * FROM BLEH WHERE BLEH='BLEH' ORDER BY NUM ASC");

now when it prints out I get 0,1,10,11,12,13,14,15,16,17,18,19,2,20

I need to have it read as 0,1,2,3,4,5,6,7 etc etc...

Ideas?

Thanks in advance...

Me.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 30 September 2005 - 07:12 PM

Is the field defined as a character (varchar, text, char) or a number? If it is a character that is the correct ascii sort, to get what you want, make the field a number (int).

Ken

#3 PureEvil

PureEvil
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 September 2005 - 07:19 PM

Is the field defined as a character (varchar, text, char) or a number? If it is a character that is the correct ascii sort, to get what you want, make the field a number (int).

Ken

View Post



I thought of that but I need it to be alphanumbaric.

because it might end up being A1, A7, A2 someday


#4 tharagleb

tharagleb
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 September 2005 - 07:45 PM

So how do you want it to sort these values:

1,11,2,20,A1,A20,A2 ?

If you have these values you *have* to do an alpha sort. If I were you I would make the field numeric and forget about what it *might* be in the future. Either that or left zero fill your data before sticking it into the database:

0001
0011
0002
00A1

Etc.

Good luck.

#5 PureEvil

PureEvil
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 September 2005 - 08:03 PM

this was solved by changing ORDER BY NUM to ORDER BY (NUM+0)

the varchar field didnt have to be changed...

Thanks for the help.

#6 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 30 September 2005 - 08:04 PM

this was solved by changing ORDER BY NUM to ORDER BY (NUM+0)

the varchar field didnt have to be changed...

Thanks for the help.

View Post

but that wouldn't work with A10...
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users