Amezis 0 Report post Posted March 28, 2006 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: 122334567998 But I want the numbers to be ordered like this:123792398456 How can I do that? Share this post Link to post Share on other sites
adriantc 0 Report post Posted March 28, 2006 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 456That 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... Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted March 28, 2006 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. Share this post Link to post Share on other sites
Amezis 0 Report post Posted March 28, 2006 (edited) 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 ) Edited March 28, 2006 by Amezis (see edit history) Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted March 28, 2006 Okay, then I'll close this one down. Share this post Link to post Share on other sites