robrayner Posted April 15, 2013 Share Posted April 15, 2013 Hi All This was working fine until the rma number reached the 1000 mark and now it is putting all the 1000 numbers with the 1's so you have to scroll all the way down the list to find the latest number. Is there away to stop this from doing this? $query1 = "SELECT DISTINCT RMA FROM rmatable where RMA like 'RMAD%' ORDER BY RMA DESC"; $result1 = mysql_query($query1); $num_rows=mysql_num_rows($result1); while ($row=mysql_fetch_array($result1)) { $RMA = $row["RMA"]; $row_ID = "$RMA"; echo "<option value=\"$row_ID\">$row_ID</option>"; } echo "</select>"; ?> Thanks Rob. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 15, 2013 Share Posted April 15, 2013 change your database table column to an integer datatype. it's a character type now and that's how strings sort/order themselves. Quote Link to comment Share on other sites More sharing options...
akphidelt2007 Posted April 15, 2013 Share Posted April 15, 2013 I actually had this problem one time and found the answer through google. But, the correct answer is the one above where you should change the data type to an integer field. But if you don't want to you can add an ABS() to the order by column and it should order it as integers... $query1 = "SELECT DISTINCT RMA FROM rmatable where RMA like 'RMAD%' ORDER BY ABS(RMA) DESC"; Quote Link to comment Share on other sites More sharing options...
akphidelt2007 Posted April 15, 2013 Share Posted April 15, 2013 Wait a second, I see what you are doing... you have the field names like RMAD1... RMAD2... RMAD1000? If that's the case then you really need to change the column or sort it on the PHP side by extracting the integer. Quote Link to comment Share on other sites More sharing options...
robrayner Posted April 16, 2013 Author Share Posted April 16, 2013 Does the integer column type like having letters and numbers put into it? Quote Link to comment Share on other sites More sharing options...
abrahamgarcia27 Posted April 16, 2013 Share Posted April 16, 2013 (edited) Interger Type : "is a number that can be written without a fractional or decimal component" Edited April 16, 2013 by abrahamgarcia27 Quote Link to comment Share on other sites More sharing options...
robrayner Posted April 16, 2013 Author Share Posted April 16, 2013 so numbers only then? Quote Link to comment Share on other sites More sharing options...
abrahamgarcia27 Posted April 16, 2013 Share Posted April 16, 2013 Try this ORDER BY CAST(`RMA` AS SIGNED) DESC Quote Link to comment Share on other sites More sharing options...
Barand Posted April 16, 2013 Share Posted April 16, 2013 you can sort within PHP using natsort $x = array ('RMAD1', 'RMAD2', 'RMAD200', 'RMAD2000', 'RMAD1000', 'RMAD100' ); natsort($x); /************* results ****** Array ( [0] => RMAD1 [1] => RMAD2 [4] => RMAD100 [2] => RMAD200 [3] => RMAD1000 [5] => RMAD2000 ) */ Quote Link to comment Share on other sites More sharing options...
robrayner Posted April 17, 2013 Author Share Posted April 17, 2013 The natsort($rma); worked but now you have to scroll to the bottom to find the latest rma number is there a way you can get it to display like this RMAD1000 RMAD999 RMAD998 and so on Instead of RMAD100 RMAD101 ...... RMAD998 RMAD999 RMAD1000 Thanks Rob Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 17, 2013 Share Posted April 17, 2013 array_reverse Quote Link to comment Share on other sites More sharing options...
Barand Posted April 17, 2013 Share Posted April 17, 2013 $x = array_reverse($x); Quote Link to comment Share on other sites More sharing options...
robrayner Posted April 17, 2013 Author Share Posted April 17, 2013 How would i implement array_reverse into this $query1 = "SELECT DISTINCT RMA FROM rmatable where RMA like 'RMAD%'"; $result1 = mysql_query($query1); $num_rows=mysql_num_rows($result1); while ($row=mysql_fetch_array($result1)) { $RMA = $row["RMA"]; $row_ID = "$RMA"; natsort($RMA); echo "<option value=\"$row_ID\">$row_ID</option>"; } echo "</select>"; Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 17, 2013 Share Posted April 17, 2013 You need to try first. Do you understand how PHP functions work? It has nothing to do with your query. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 17, 2013 Share Posted April 17, 2013 First you need an array to sort $query1 = "SELECT DISTINCT RMA FROM rmatable where RMA like 'RMAD%'"; $result1 = mysql_query($query1); $num_rows=mysql_num_rows($result1); while ($row=mysql_fetch_array($result1)) { $rma_array[] = $row["RMA"]; // build array } Quote Link to comment Share on other sites More sharing options...
robrayner Posted April 19, 2013 Author Share Posted April 19, 2013 I must admit that i only know the basics of php, I am self taught and not that up to speed with it. "Do you understand how PHP functions work? " Not really. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 19, 2013 Share Posted April 19, 2013 So, step one is go read the PHP manual section on functions. http://us2.php.net/functions Then maybe also go read about arrays. Quote Link to comment 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.