Hi there,
At the moment I'm just about there with some search functionality, searching mainly on a lengthy CV type field. For this reason, the field itself only appears on the details page, not the results page.
I need the search terms to highlight in the CV field, and have this working fine, passing it through as part of the URL variable :
<a href="candidateDetails3.php?CandidateID=<?php echo $row_Recordset1['CandidateID']; ?>&keyword=<?php echo ($_POST['keyword']); ?>"><?php echo $row_Recordset1['FirstName']; ?> <?php echo $row_Recordset1['LastName']; ?></a>
This works fine with search strings not in quotes, but not with strings with quotes (that are used to search for phrases, rather than words).
If you search on :
proven track record
to search for any of the three words, the end of the link is correct as :
...keyword=proven track record"
but if you search on :
"proven track record"
to find instances of the exact phrase, then the end of the link is given as :
...keyword=\"
And the code at the top of the page that is sorting out the search terms in quotes looks like :
<?php function highlightResult($keyword,$result) {
if (get_magic_quotes_gpc()) {
$replace = stripslashes($keyword);
}
else {
$replace = $keyword;
}
$replace = preg_replace("/\"|\,/i","",$replace);
$replace = preg_replace("/ {2,}/i"," ",$replace);
$replaceArr = explode(" ",$replace);
for ( $i = 0; $i < sizeof($replaceArr); $i++ ) {
$result = preg_replace("/{$replaceArr[$i]}/i","<b>{$replaceArr[$i]}</b>",$result);
}
$highlighted = $result;
return $highlighted;
}
?>
So basically I was wondering if I need to use a session variable here to pass it through? I haven't really used these before tho', so am unsure as to how to go about it.
If anyone could point me in the right direction, or post some sample code for how to capture it in the first place on the results page, and then grab it again so that the phrases are highlighted on the details page, that would be great.
Cheers.