Germaris Posted January 25, 2008 Share Posted January 25, 2008 Hi there! Where and how can I implement, in the code below, a natsort() function to get volume as: 1 2 3 10 12 21 23 instead of 1 10 12 2 21 23 Many thanks in advance for any help! Regards, Gerry function papier($unlock) { GLOBAL $db; $table = "_library"; $query =mysql_query("SELECT * FROM $table WHERE issued='1' ORDER BY volume DESC"); if (!$query) { print "&contenu=Le serveur est indisponible."; } else { if ( mysql_num_rows( $query ) > 0 ) { while ($row = mysql_fetch_array( $query )) { $flashstr .= "<font color='#000000'>"."<b>".$row ["mainTitle" ]."</b>"."</font>".", vol. ".$row ["volume" ].", n° ".$row ["section" ]."<font color='#FF0000'>".$row ["soldout" ]."</font>"."<br />"; } print ("&instruction=blah-blah-blah"."&contenu=".urlencode(stripslashes($flashstr))) ; } else { print "&contenu=blah-blah-blah"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/87802-natural-order/ Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 what data type is 'volume' in the database table? if it's not sorting right, i assume it's a varchar, in which case you should change it to an integer Quote Link to comment https://forums.phpfreaks.com/topic/87802-natural-order/#findComment-449102 Share on other sites More sharing options...
Germaris Posted January 25, 2008 Author Share Posted January 25, 2008 DONE ! It works. Thank you very much! However, I have another problem... In my real world query, I ask for "(... ORDER by volume, section DESC"); Let me explain a bit: volume stands for issues of a bi-annual magazine (twice a year) section stands for parts of a volume - 1 for a single issue (single priced) - 2-3 for a double issue (double priced) section also can be 1-2 and 3 When I ask for order like defined above, the descending sorting is good for volume but not for section. For example, the result displays for volume 14 section 1 before 2-3. It should be volume 14, section 2-3 then volume 14, section 1 How can I solve this? The section column can't be an INT column... Quote Link to comment https://forums.phpfreaks.com/topic/87802-natural-order/#findComment-449161 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.