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' or
T_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']);