note 19795 added to function.array-multisort
| From: | developer at i-space dot org | Date: | Mon, 11 Mar 2002 14:23:31 +0000 |
| Subject: | note 19795 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27623@lists.php.net to get a copy of this message | ||
if you want to sort the results from a sql query - from two or more tables (especially MySQL)
(which has a FULLTEXT indexing - good for search engines :)
and if you have one array with the results and other with the scores, retrieved with :
SELECT what-you-want MATCH fields AGAINST ('$term')
AS score FROM table WHERE MATCH (fields)
AGAINST ('$term') ORDER BY 'score' ASC
you can make a array from these two - $ar = array($scores, $results);
(check if $scores is array - else PHP will return error)
then you make :
array_multisort($ar[0], SORT_NUMERIC, SORT_DESC, $ar[1], SORT_STRING, SORT_DESC);
which will sort the results by their score - relevancy ... after that you make you r final array -
$final_results = $ar[1];
and you have a results sorted by relevancy very good for search scripts :)
--
http://www.php.net/manual/en/function.array-multisort.php
http://master.php.net/manage/user-notes.php?action=edit+19795
http://master.php.net/manage/user-notes.php?action=delete+19795
http://master.php.net/manage/user-notes.php?action=reject+19795