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
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!

Edited by phpjayx
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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