phpjayx Posted May 8, 2013 Share Posted May 8, 2013 {$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 Quote Link to comment https://forums.phpfreaks.com/topic/277781-sorting-numbers-problem/ Share on other sites More sharing options...
phpjayx Posted May 8, 2013 Author Share Posted May 8, 2013 (edited) 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 May 8, 2013 by phpjayx Quote Link to comment https://forums.phpfreaks.com/topic/277781-sorting-numbers-problem/#findComment-1429032 Share on other sites More sharing options...
kicken Posted May 8, 2013 Share Posted May 8, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/277781-sorting-numbers-problem/#findComment-1429061 Share on other sites More sharing options...
fenway Posted May 12, 2013 Share Posted May 12, 2013 You can also use +0. Quote Link to comment https://forums.phpfreaks.com/topic/277781-sorting-numbers-problem/#findComment-1429772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.