note 24080 deleted from function.array-multisort by aidan
| From: | aidan@php.net | Date: | Sun, 03 Oct 2004 10:58:42 +0000 |
| Subject: | note 24080 deleted from function.array-multisort by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77810@lists.php.net to get a copy of this message | ||
Note Submitter: jpirkey at email dot com
----
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.