0

I have added my code below, i am new to php and mysql and trying to search mysql using php based on user inputs and working really fine. But not sure how to highlight the user input value while displaying from mysql.

$output = NULL;
if(isset($_POST['submit'])){
$mysqli = new mysqli("localhost","root","","test");
$search = $mysqli->real_escape_string($_POST['search']);
$resultSet = $mysqli->query("SELECT * FROM books WHERE BookContent LIKE '%$search%'");
if($resultSet->num_rows>0){
    while($rows = $resultSet->fetch_assoc()){
        $BookContent = $rows['BookContent'];
        //$output = preg_replace("/($search)/i",'<span class="highlight">$1</span>', $output);
        echo $output = "" ."Your search results-->  $BookContent"."<br>";
    }

}else{
    echo $output = "No result" ;
}

} ?>

1 Answers1

1

just add this in your page.

CSS:

.highlight{background-color:yellow}

jQuery:

$("body").highlight("<?php echo $search; ?>");