I'm working on mini project where the words from the description are highlighted on the webpage. The keywords are inputted by the user dynamically in to the database.
While displaying data into webpage the description and keywords are selected from data base and the words in description which match the keywords are highlighted.
Database image:
Table name information
table name keywords
Here is the code
<?php
$link = new mysqli('localhost','root','','example');
if($link->connect_error){
die("Connection Failed".$link->connect_error);
}
?>
<!DOCTYPE html>
<html>
<head>
<style>
.highlight{
color:green;
background:yellow;
}
</style>
</head>
<body>
<?php
//select keywords
$sql = "SELECT keywords FROM keywords";
if($res = $link->query($sql)){
while($row = $res->fetch_assoc()){
$keyword[] =array(
'name'=>$row['keywords'],
);
}
}
else
{
echo "Error".$link->error;
}
//get the description
$Query = "SELECT * FROM information";
if($result = $link->query($Query)){
while($rows = $result->fetch_assoc()){
echo $rows['description']."<br><br><br>";
}
}
else
{
echo "error".$link->error;
}
?>
</body>
</html>
here is the my output look like
Now here is how it show be looking