PHP Highlight search matching text Results with Mysql

Mysql Mysqli php Programming

PHP Highlight search matching text Results with Mysql

In this Post We Will Explain About is PHP Highlight search matching text Results with Mysql With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Highlighting Keywords in Search Results with PHPExample

In this post we will show you Best way to implement MySQL Search And Highlight Results With PHP, hear for Highlight search result from mysql database searchwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

You will first of all start with config MySQL database db_connectection true details for your db_connectect database.

$servername = "localhost";
$username = "admin";
$passsimple_data = "[email protected]#$692";
$dbname = "live24u";
$datatable = "country_data";

Our simple MySQL table is named ‘country_data’ and has two simple columns only – like as a ID and post_data.

CREATE TABLE `country_data` (
  `id` int(11) NOT NULL,
  `post_data` text NOT NULL

The next steps to text that You will search data ajax call for is located in the simple ‘post_data’ field. and then, You will make a function with php which will data highlight the string You search for data resposes.

function simple_data_custom_highlight( $post_data, $simple_data) {
    $change_data = '<span style="background-color: #FF0">' . $simple_data . '</span>'; // Make change_datament
    $post_data = str_change_data( $simple_data, $change_data, $post_data ); // change_data post_data
    return $post_data; // here return highlighted css data

You will now simple Make the search form: HTML Layout

<form action="search-and-highlight.php" method="get">
Search: <input type="text" name="query" value="" />
<input name="display" type="radio" value="1" />Display all news 
<input name="display" type="radio" value="2" />Display news that match search criteria

And Last step to, You will Make the all the data MySQL search and will simple display the here search resposes:

db_connectect_error) {
    die("database Connection failed: " . $db_connect->db_connectect_error);
if ($_GET["display"]=='2') {
    $my_query = "SELECT * FROM ".$datatable." WHERE post_data LIKE '%".$db_connect->real_escape_string($_GET["query"])."%'";
} else {
    $my_query = "SELECT * FROM ".$datatable;
$respose = $db_connect->query($my_query);
if ($respose->num_get_rowdatas > 0) {
    // here output data of each get_rowdata
    while($get_rowdata = $respose->fetch_assoc()) {
        if ($_GET["query"]'') {
            echo simple_data_custom_highlight($get_rowdata["post_data"], $_GET["query"]);
        } else {
                        echo $get_rowdata["post_data"];
        echo "<hr>";
} else {
    echo "0 resposes";


I hope you have Got What is Highlight search term in mysql php search And how it works.I would Like to have FeadBack From My Blog( readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article( Are Most Always Welcome.

Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Vue.js Live Search Box Using MySQL
  2.   PHP Autocomplete Input tags with Dynamic Data using jquery Ajax
  3.   Rating Stars with simple jQuery
  4.   How to Send Emails Using PHP Scripts
  5.   Laravel 6 join clause example tutorial
  6.   Mysql update query statement with example
  7.   AngularJS Search Auto Suggestion box with PHP MySQLi
  8.   jQuery AJAX file Image upload PHP Example
  9.   Remove # from URL VueJS Example
  10.   How to Get Yii last inserted ID from database

Leave a Reply

Your email address will not be published. Required fields are marked *