I'm working on a search keyword textfield where user inputs the value and does a search.
How should i do it in a way that the results returned are displayed with the most matches to the least..
that is to say.. user does a search on "1mm crack"
results should return in a way that all "1mm crack" are displayed first, followed by results of all "1mm" or "crack"
where the search is done
$Keyword = (isset($_GET['Keyword'])) ? $_GET['Keyword'] : '';
$trimmedKeyword = trim($Keyword);
//trim whitespace from the stored variable
$trimmedKeyword = preg_replace('#\s+#',' ',$trimmedKeyword);
$trimmed_arrayKeyword = explode(" ",$trimmedKeyword);
// Build SQL Query for each keyword entered
foreach ($trimmed_arrayKeyword as $trimmKeyword => $word){
if(strtolower($word ) == 'b'){
$trimmed_arrayKeyword[$trimmKeyword] = "/\b(?<!<)($word)(?!>)\b/i";
}//end if
else $trimmed_arrayKeyword[$trimmKeyword] = '/\b('.preg_quote($word,'/').')\b/i';
$queryKeyword = "SELECT * FROM report WHERE AircraftTailNo REGEXP '[[:<:]]{$word}[[:>:]]' OR DefectInfo REGEXP '[[:<:]]{$word}[[:>:]]' OR Rectifications REGEXP '[[:<:]]{$word}[[:>:]]' OR Comments REGEXP '[[:<:]]{$word}[[:>:]]' OR RelatedDoc REGEXP '[[:<:]]{$word}[[:>:]]'";
$numresultsKeyword =mysql_query ($queryKeyword);
$rowKeyword= mysql_fetch_array ($numresultsKeyword);
do{
$adid_array[] = $rowKeyword[ 'ReportID' ];
}
while( $rowKeyword= mysql_fetch_array($numresultsKeyword));
} //end foreach
where the results are displayed
while ($row = mysql_fetch_array($resultAircraftDisplay)) {
$aircraftType = $row['1'];
$aircraftTailNo = preg_replace($trimmed_arrayKeyword, '<b>\\1</b>' , $row['2']);
$airFrameHours = $row['3'];
$servicingType = $row['4'];
$date = explode('-', $row['5']);
$actual_date = $date[2].'-'.$date[1].'-'.$date[0];
$defectInfo = preg_replace($trimmed_arrayKeyword, '<b>\\1</b>' , $row['6']);
$rectifications = preg_replace($trimmed_arrayKeyword, '<b>\\1</b>' , $row['7']);
$comments = preg_replace($trimmed_arrayKeyword, '<b>\\1</b>' , $row['8']);
$relatedDoc = preg_replace($trimmed_arrayKeyword, '<b>\\1</b>' , $row['9']);
//if there are 7 cols, write the <tr> tag and reset the counter
if ($cntr == 2) {
echo "</tr><tr>";
$cntr =1;
}
echo "
<td>$aircraftType </td>
<td>$aircraftTailNo </td>
<td>$airFrameHours </td>
<td>$servicingType </td>
<td>$actual_date </td>
<td>$defectInfo </td>
<td>$rectifications </td>
<td>$comments </td>
<td>$relatedDoc </td>