I’m having trouble highlighting a search term within a query. If a user searches “Jesus”, all verses that contain “Jesus” will be listed and paginated. I want to highlight the search query in all of these passages.
Let’s say I search for “Jesus”, and some 10 verses pop up, I want all instances of Jesus on every page to be highlighted.
My PHP code:
index: http://pastebin.com/vTdy79er
bible database: http://www.mediafire.com/?00x4fnbn1vr4nch
I have no idea how to go about doing this.
my select statement for my queries:
$searchResult = $dbLink->prepare("SELECT bsect, bname, bnum, cnum, vnum, vtext, MATCH (bname, vtext)
AGAINST ('$searchQuery' IN BOOLEAN MODE)
AS relevance
FROM kjv
WHERE MATCH (bname, vtext)
AGAINST ('$searchQuery' IN BOOLEAN MODE)
ORDER BY relevance
DESC
$limit");
The code that actually displays my results (bible name chapter number : verse number and then verse text:
while ($searchResult->fetch())
{
print ("<span class=\"results title\">$bname $cnum:$vnum</span>");
print ("<p class=\"passage\">$vtext</p>");
}
I believe you already do it here:
even if I would suggest to change the code like this:
or even better, use a
<span>tag and a class, and then assign all the CSS that you want to that class and make it easier to change in the futureEDIT/ADD
with your last updated message, this is what you have to do (if I understand your code correctly)
change it to (assuming that
$searchQueryis the variable that contain that string that is searched forI also like better echo than print, but is personal preference. For sure you want to avoid the
"and use the'when possible as it will speed up PHP as the engine will not have to parse the whole string to find variables.. but again, personal preference