FW: RE: [PHP] highlighting search results (revisited)

From: Date: Wed, 18 Apr 2001 07:47:47 +0000
Subject: FW: RE: [PHP] highlighting search results (revisited)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49146@lists.php.net to get a copy of this message
> The input from the search form is $searchtext. The Returned > Search data is > $searchdata. > > <? > > $sql = "SELECT searchdata FROM table WHERE searchdata LIKE > '%$searchtext'"; > $result = @mysql_query($sql, $connection) > or die (mysql_error()); > > $num = mysql_num_rows($result); > > $x = 0; > > if ($num == 0) { > echo "No results"; > } else { > > while($row = mysql_fetch_array($result)) { > $searchdata = $row['searchdata']; > > $x++; > > $searchdata = eregi_replace("$searchtext", "<font > color=\"#FF0000\">$searchtext</font>", $searchdata); > > echo "$x. $searchdata"; > > } > > } > > ?> > > Make sense? And does it help? Hi James Yes and no. I've got it to do that but what if the user enters more than one word? I need to be able to loop inside the while for each word to be able to highlight it. I think! The problem is if someone enters a word which is used within the hightlighting code. ie. font in your example. This would then hightlight this again and screw the resulting code. M@

« previous php.general (#49146) next »