|
|
|
|
![]() ![]() |
Mar 28 2006, 01:51 PM
Post
#1
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 535 Joined: 14-February 05 From: Oslo, Norway Member No.: 3,759 |
I am making a MySQL-driven list. It can be ordered by name or by a number in the table. However, it orders the numbers like this:
CODE 1 2 23 3 456 7 9 98 But I want the numbers to be ordered like this: CODE 1 2 3 7 9 23 98 456 How can I do that? |
|
|
|
Mar 28 2006, 02:22 PM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 498 Joined: 31-January 05 From: Bucharest, Romania Member No.: 3,516 |
I'm n ot an expert in MySQL, but the answer is pretty simple. It orders it that way because of the way the variables in the table are. If, for example you choose varchar(x) it will give you: 1 2 23 3 456 7 9 98 instead of: 1 2 3 7 9 23 98 456
That is because it takes in consideration the first letter of the word (number in our case). If they happen to match the difference it made by the second letter. If that also happens to match it check the third ... and so on. And since 1<2<3<4<5<6<7<8<9<0 (in ASCII code) you understand why it orders them in that way (why 3 for example is bigger then 23). If you want to order them as you want: 1 2 3 7 9 23 ... you just have to change the type from varchar(x) or whatever char value are you using to int(x) (int comes from integer). Since int means only numbers it doesn't care about the first letter and takes the hole number and order them. So there is no need to change the code, just change the type. Hope you understand... |
|
|
|
Mar 28 2006, 02:27 PM
Post
#3
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,753 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
arre you using an "ORDER by" in the mysql statement? Maybe paste the statement you are using in to a posting and we'll have a better grasp of what you are trying to do.
|
|
|
|
Mar 28 2006, 02:29 PM
Post
#4
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 535 Joined: 14-February 05 From: Oslo, Norway Member No.: 3,759 |
Thanks alot adriantc! It works now.
By the way, I can't believe that I set it to varchar Jlhaslip, I had to simply change the table type to int (I had it on varchar This post has been edited by Amezis: Mar 28 2006, 02:31 PM |
|
|
|
Mar 28 2006, 02:33 PM
Post
#5
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,753 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
Okay, then I'll close this one down.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 16th May 2008 - 02:57 PM |