Jump to content

sorting numbers problem


phpjayx

Recommended Posts

    {$sql_select = "select * from data where valid='1' and userid='" . $param['userid'] . "' order by number2, timestamp asc";}

 

 

 

The above code sorts on the "number2", except when the numbers are 10 or above it is only sorting by the first number....

 

 

So if I had a list of the following the order is

 

 

1

1

1

10

11

11

12

2

20

21

3

4

5

 

etc

 

Any help would be appreciated!!!

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/277781-sorting-numbers-problem/
Share on other sites

Well I just found one solution.... to just put a (number2 *1).  This solved it.....

 

I saw on another site someone posted to use....CAST(column AS DECIMAL).  But I felt like the other was simpler...

 

If there are any drawbacks to using the *1 method, please let me know.

 

 

Thanks!

Your problem is that your number2 column is the wrong datatype. You should change it's type to be one of the numeric types (INT,DOUBLE,etc, whatever is appropriate for the values stored). Once you do that it will sort them correctly without the need for a hack like your currently using.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.