Could someone please help me to highlight the searchterm in my php search code? Below is the code that I am currently using, and it works fine. Would just like to add a high
The simplest solution is to use str_replace() to replace the search term with tags wrapped around them, styled.
Warning: The way you have your script set up, you're vulnerable to injection attacks. This is just an example to show you how to pass in variables.
See: How can I prevent SQL injection in PHP?
";
echo "
";
echo "";
echo "
";
echo "Your search has found ";
echo "$num_rows";
echo " records.
";
echo "
";
echo "
Signed in By
Reference Number
Asset Number
Make Model
Serial Number
Operating System
Office
Profile
Extra Apps
Time IN
Status
Time OUT
";
while($row = mysql_fetch_array($result))
{
echo "";
echo "" . str_replace($term, "$term", $row['who']) . " ";
echo "" . str_replace($term, "$term", $row['ref']) . " ";
echo "" . str_replace($term, "$term", $row['asset']) . " ";
echo "" . str_replace($term, "$term", $row['make_model']) . " ";
echo "" . str_replace($term, "$term", $row['serial']) . " ";
echo "" . str_replace($term, "$term", $row['os']) . " ";
echo "" . str_replace($term, "$term", $row['office']) . " ";
echo "" . str_replace($term, "$term", $row['swp']) . " ";
echo "" . str_replace($term, "$term", $row['ea']) . " ";
echo "" . str_replace($term, "$term", $row['dt_in']) . " ";
echo "" . str_replace($term, "$term", $row['status']) . " ";
echo "" . str_replace($term, "$term", $row['dt_out']) . " ";
}
echo "
";
echo "
";
echo "";
mysql_close($con);
?>
And some sample styling: