Sorting output of MySQL Select Like queries

From: Date: Thu, 01 Nov 2001 22:28:54 +0000
Subject: Sorting output of MySQL Select Like queries
Groups: php.db 
Request: Send a blank email to php-db+get-13923@lists.php.net to get a copy of this message
Can someone help me understand the problem with the approach I am trying or suggest a new approach? Basic Objective: Search several fields of a table for keywords/search terms and return the ID's for records containing those keywords. I would like to then sort those ID's in descending order of the number of times there is a match. Approach: (Note: because my host has not updated My SQL, I cannot use the Match function) I am searching each table field for each search term then merging the resulting arrays. I then perform an "array_count_values" on the final array to determine frequency, "rsort" that to get descending order. See query function script after Problems. Problems: 1) I get the following error message when the "array_count_values" function is reached:: Can only count STRING and INTEGER values! This is because the values in the array are also arrays but I don't know how to convert them to the single values. 2) How do I reverse sort and convert the associative array that is generated by "array_count_values" back to the ID's that have become keys? Query Funciton Example: $test_array=Search_Titles($item); $count_array=array_count_values($test_array); function Search_Titles($item) { //get candidates saved group preferences $sql="SELECT CID FROM abbreviated WHERE CSkills like '% $item%'"; $result = @mysql_query($sql) or die("Couldn't execute title match query."); if (!$result) return false; $num_groups = @mysql_num_rows($result); if ($num_groups ==0) return false; // create an array of groups $result = db_result_to_array($result); return $result; } Please reply to my email address as well as the newsgroup: rickrobins@jobsinmotorsports.com Thanks, Rick

« previous php.db (#13923) next »