PHP Highlight search matching text Results with Mysql

PHP Highlight search matching text Results with Mysql

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 Pakainfo.com – 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!.

  Simple Laravel Contact Us Form With Email Example

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

<?php
error_reporting(0);
$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
</form>

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

  Ajax PHP MySQL Creating Autocomplete Search Suggestion

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";
}
$db_connect->close();
?>

Example

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(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.