Hi,
I've searched the boards and can't quite work this out.
I have a form where the user can enter one or more descriptive words
about a person, such as "black white blue". The script breaks the user-entered words into an array, then steps through that array and searches each row's "name" and "description" columns, to see if the word is included in the "description".
The result should look like this:
Matches for "black":
(name)
(name)
Matches for "white":
(name)
(name)
(name)
Matches for "blue":
(name)
The description word will sometimes occur for more than one name,
meaning several names might have the word "black" in the description column.
The problem is that it only returns the first match found.
$user_array = explode(" ", $tertiary); //make array of user-entered words
for($j=0; $j<count($user_array); $j++) {
$result_name_array[$j] = "Matches for $user_array[$j]:<br>\n";
$tertiary_query = "SELECT name, tertiary FROM $ftable WHERE tertiary LIKE '%$user_array[$j]%'";
$result = mysql_query($tertiary_query);
$row = mysql_fetch_row($result);
$result_name_array[$j] .= "$row[0]<br>\n";
}
I also tried nesting for loops, to loop through each row an amount of times equal to the number of elements in the $user_array:
for($j=0; $j<count($user_array); $j++) {
$result_name_array[$j] = "Matches for $user_array[$j]:<br>\n";
for($i=0; $i<$numresults; $i++) {
$row = mysql_fetch_row($result);
$match = $row[1];
if (eregi("\w*\s?$user_array[$j]\s?\w*", $match)) {
$result_name_array[$j] .= "$row[0]<br>\n";
}
}
}
That version gives all rows that contain "black", but stops after "black" and won't search for "white" or "blue".
No method so far can get past one set of results. It works fine with only one word, but not with more than one.
Using fulltext doesn't help.
I've searched everywhere for an answer; maybe it's very obvious???
Any help greatly appreciated.