Jump to content

Recommended Posts

Hi

 

I would like to highlight the keyword in the search result on my page but am not sure how do achieve this.  I have been playing with my code for a while without success.  Here is the code:

 

<?php
$mytime = time() + 3600;  //convert to BST
$mytimestamp = date('Y-m-d H:i:s', $mytime);

$selection = $_GET["day_selected"];
if($_GET["search_all"]!="")
{$search = $_GET["search_all"];

 $result = mysql_query("
SELECT ItemAddedTime,ItemTitle,ItemLink,ItemSourceURL,ItemDescription
FROM feedItems
WHERE DATEDIFF('$mytimestamp', `ItemAddedTime`) <= 13
AND ItemTitle LIKE '%$search%'
ORDER BY ItemAddedTime DESC", $connection);  

if(!$result){ die("Database selection failed: " . mysql_error()); } 

$num_rows = mysql_num_rows($result); 
If($num_rows > 0){
echo "<table width='100%'><tr><td><b>Search results</b></td></tr>";
echo "<table width='100%'><tr><td><img src='./images/greyline.jpg' width='100%' height='1'></td></tr>";
while($row = mysql_fetch_array($result)){
$linksource=findLinkSource( $row[3] );
$mydate = date('H:i',strtotime($row[0]));
echo "<tr><td>$mydate <A href=$row[2] target='blank'>$row[1]</A> $linksource</td></tr>";} 
echo"</table><br />";
} 
exit();}

?>
[/code

So basically I want to highlight any word that matches $_GET["search_all"] in the results.  Any help would be appreciated.

Thanks
Damian

   $mydate = date('H:i',strtotime($row[0]));
   $linksource = str_replace($search, "<span>{$search}</span>", $linksource);
   echo "<tr><td>$mydate <A href=$row[2] target='blank'>$row[1]</A> $linksource</td></tr>";} 

 

Should take care of it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.