note 24080 modified in function.array-multisort by vrana

From: Date: Tue, 17 Aug 2004 14:41:48 +0000
Subject: note 24080 modified in function.array-multisort by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79908@lists.php.net to get a copy of this message
To: salim@codesplash.com Another option is to modify the SQL statement and not use the array_multisort function. MySQL supports the ORDER BY clause. For instance: //Get table sorted on field2 output into $result1 and $result2 array <?php // ascending order by field2 $result1 = mysql_query("SELECT field1, field2 FROM table ORDER BY field2"); // descending order by field2 $result2 = mysql_query("SELECT field1, field2 FROM table ORDER BY field2 DESC"); ?> Note: I have not benchmarking to determine whether PHP is faster in sorting or MySQL. It would be worth some investigation if you are using large tables. Hope this helps. --was-- To: salim@codesplash.com Another option is to modify the SQL statement and not use the array_multisort function. MySQL supports the ORDER BY clause. For instance: //Get table sorted on field2 output into $result1 and $result2 array // ascending order by field2 $result1 = mysql_query("SELECT field1, field2 FROM table ORDER BY field2"); // descending order by field2 $result2 = mysql_query("SELECT field1, field2 FROM table ORDER BY field2 DESC"); Note: I have not benchmarking to determine whether PHP is faster in sorting or MySQL. It would be worth some investigation if you are using large tables. Hope this helps. http://php.net/manual/en/function.array-multisort.php

« previous php.notes (#79908) next »