Results 1 to 2 of 2

Thread: Natural order

  1. #1
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57

    Unanswered: Natural order

    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


    Code:
    function papier() 
    {
    		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&#176; ".$row ["section" ]."<font color='#FF0000'>".$row ["soldout" ]."</font>"."<br />";
    				}
    				print ("&instruction=blah-blah-blah"."&contenu=".urlencode(stripslashes($flashstr))) ;
    			}
    			else {
    				print "&contenu=blah-blah-blah";
    			}
    		}
    }

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    your main problem is that you want to impose a numerical sort order on text.

    so either you need to make sure your numeric data is stored in a numeric field, whihc would in MHV the 'correct' resolution

    or

    you insert spaces or zeros to pad the number accordingly

    the alternative may be to knock up some kludgey function to attempt to resolve what the string number is and pad accordingly, but that would be fixing the symptoms not the root cause of the problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •