note 19795 rejected from function.array-multisort by danbeck

From: Date: Wed, 13 Mar 2002 15:57:59 +0000
Subject: note 19795 rejected from function.array-multisort by danbeck
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-27743@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 :)

« previous php.notes (#27743) next »