I'm currently working on a keyword search texfield..
I have trouble trying to search for exact word, that is to say if user
searches for "crac" instead of "crack".. it should not display any results..
So what i did was to use the codes below for my query search on exact keywords , but it returned me an error statement

Parse error: parse error, expecting T_STRING' orT_VARIABLE' or `T_NUM_STRING' in c:\inetpub\wwwroot\searchCriteria.php on line 236

Line- 236

$queryKeyword = "SELECT * FROM report WHERE AirCraftType REGEXP '[[:<:]]$word[[:>:]]' OR AircraftTailNo REGEXP '[[:<:]]$word[[:>:]]' OR ServicingType REGEXP '[[:<:]]$word[[:>:]]' OR DefectInfo REGEXP '[[:<:]]$word[[:>:]]' OR Rectifications REGEXP '[[:<:]]$word[[:>:]]' OR Comments REGEXP '[[:<:]]$word[[:>:]]' OR RelatedDoc REGEXP '[[:<:]]$word[[:>:]]'";

The other thing is ..
if i were to do a search on " 1mm crack" and in between the "1mm" and the "crack" there were extra spaces..
For example.. "1mm spaces spaces spaces spaces Crack"..

results that were returned were displayed like this..

<b>b>This<b>b> <b>b>is<b>b> <b>b>a<b>b> <b>b>1mm<b>b> <<b>b>b<b>b>><b>b>Crack<b>b>b>b>b<b>b>> <b>b>situated<b>b> <b>b>at<b>b> <b>b>the<b>b> <b>b>DB<b>b> <b>b>Engine<b>b> <b>b>Latch<b>b> <b>b>Cowling<b>b> 

all the extra <b>b> <b>b> were shown between with the results..

 // Get the search variable from URL For Keyword Search
  $Keyword = (isset($_GET['Keyword'])) ? $_GET['Keyword'] : '';
//trim whitespace from the stored variable
  $trimmedKeyword = trim($Keyword);
//separate key-phrases into keywords
  $trimmed_arrayKeyword = explode(" ",$trimmedKeyword);

foreach ($trimmed_arrayKeyword as $trimmKeyword => $word){
$trimmed_arrayKeyword[$trimmKeyword] = '/\b('.preg_quote($word,'/').')\b/i';  
// EDIT HERE and specify your table and field names for the SQL query $queryKeyword = "SELECT * FROM report WHERE AirCraftType REGEXP '[[:<:]]$word[[:>:]]' OR AircraftTailNo REGEXP '[[:<:]]$word[[:>:]]' OR ServicingType REGEXP '[[:<:]]$word[[:>:]]' OR DefectInfo REGEXP '[[:<:]]$word[[:>:]]' OR Rectifications REGEXP '[[:<:]]$word[[:>:]]' OR Comments REGEXP '[[:<:]]$word[[:>:]]' OR RelatedDoc REGEXP '[[:<:]]$word[[:>:]]'"; // Execute the query to get number of rows that contain search kewords $queryAircraftDisplay = "SELECT * from report where reportID != 0"; if (!empty($_GET['Keyword'])) { $queryAircraftDisplay .= " and reportID in ($newarr)"; } $resultAircraftDisplay = mysql_query($queryAircraftDisplay) or die ("couldn't execute query ".mysql_error()); $num=mysql_numrows($resultAircraftDisplay); $aircraftType = preg_replace($trimmed_arrayKeyword, '<b>\\1</b>' , $row['1']);
$aircraftTailNo = preg_replace($trimmed_arrayKeyword, '<b>\\1</b>' , $row['2']); $airFrameHours = preg_replace($trimmed_arrayKeyword, '<b>\\1</b>' , $row['3']);

    I'm not sure about the first one, but for the second you could use preg_replace on the query string to replace all multiple spaces with a single space before doing any other processing.

    $keyword = preg_replace('/[\s]+/' , ' ' , $keyword);

      I was able to remove all extra spacing..

      $trimmedKeyword = trim($Keyword);
      $trimmedKeyword = preg_replace('#\s+#',' ',$trimmedKeyword);
        $trimmed_arrayKeyword = explode(" ",$trimmedKeyword);
      

      Another error i notice was, if i were to search "Crack D B"

      the results that were returned.. there shouldn't have a <b> b> in between the crack..
      CODE
      This is a 2mm <b>Crackb> situated at the DB Engine Latch Cowling

      tha actual results
      CODE
      This is a 2mm Crack situated at the DB Engine Latch Cowling

        Write a Reply...