Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
    • Guest Posting Service
  • Advertise
  • About
  • Contact Us

ajax live data search using jquery php mysql

November 12, 2020 Pakainfo php, Ajax, JavaScript, jQuery, Mysql, Mysqli Leave a comment

Today, We want to share with you ajax live data search using jquery php mysql.In this post we will show you php mysql ajax search autocomplete, hear for ajax search box php mysql like google.

ajax live search jquery

Contents

  • ajax live search jquery
    • Step 1 Create the members’ table in MySQL
    • Step 2 Create Connection(config.php)
    • Step 3 index.php
    • Step 4 getData.php
    • Related posts

we will give you demo and example for implement.In this post, we will learn about PHP AJAX Live Search Box Autocomplete Using MySQL Database with an example.

Step 1: Create the members’ table in MySQL:

CREATE TABLE `members` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  `mail_address` varchar(80) NOT NULL,
  `membername` varchar(45) DEFAULT NULL,
  `cell_phone` varchar(50) DEFAULT NULL,
  `bio` text,
  `profile_pic` text,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`,`name`),
  UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Step 2: Create Connection(config.php)

<?php
//Database details
$db_host = 'localhost';
$db_username = 'username';
$db_password = 'password';
$db_name = 'database_name';

//Create connection and select DB
$conn = mysqli_connect($db_host, $db_username, $db_password, $db_name);
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

Step : 3 index.php

<!--
Used basic html and bootstrap skeleton from the below link for style purpose which contains bootstrap.css,bootstrap.js,jquery.js
https://www.w3schools.com/bootstrap/bootstrap_get_started.asp
Used bootstrap form elements from below link.
https://www.w3schools.com/bootstrap/bootstrap_forms.asp-->
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Live Demo: Ajax live data search using PHP and MySQL</title>
        <meta content='Live Demo: Ajax live data search using PHP and MySQL' name='description' />
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">      
        <style>
            .img-box{
                max-height: 300px;
                margin-bottom: 20px;
            }
        </style>
    </head>
    <body>
        <div class="container" style="max-width:800px;margin:0 auto;margin-top:50px;">  
            <div>
                <h2 style="margin-bottom:50px;">Live Demo: Ajax live data search using PHP and MySQL</h2>
                <div>
                    <div style="margin-bottom:30px;"><input type="text" class="form-control" id="query_find" placeholder="Search"/></div>
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Membername</th>
                                <th>Mobile No.</th>
                            </tr>
                        </thead>
                        <tbody id="tbl_body">
                            <?php
                            $sql = mysqli_query($conn, "SELECT * FROM members ORDER BY id LIMIT 20");
                            while ($row = mysqli_fetch_array($sql)) {
                                ?>
                                <tr>
                                    <td><?php echo $row['name']; ?></td>
                                    <td><?php echo $row['mail_address']; ?></td>
                                    <td><?php echo $row['membername']; ?></td>
                                    <td><?php echo $row['cell_phone']; ?></td>
                                </tr>
                            <?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script>
            $(document).on("keyup", "#query_find", function () {
                var query_find = $("#query_find").val();
                $.ajax({
                    url: 'getData.php',
                    type: 'POST',
                    data: {query_find: query_find},
                    success: function (data) {
                        $("#tbl_body").html(data);
                    }
                });
            });
        </script>      
    </body>
</html>

Step 4: getData.php

<?php

require_once 'inc/config.php';
if (isset($_POST['query_find'])) {
    $query_find = mysqli_real_escape_string($conn, $_POST['query_find']);
    $query = mysqli_query($conn, "SELECT * FROM members where name like '%$query_find%' or mail_address like '%$query_find%' or membername like '%$query_find%' or cell_phone like '%$query_find%' order by id limit 20");
    $output = '';
    if ($query->num_rows > 0) {
        while ($row = mysqli_fetch_array($query)) {
            $output .= '<tr>
    <td>' . $row['name'] . '</td>
    <td>' . $row['mail_address'] . '</td>
    <td>' . $row['membername'] . '</td>
    <td>' . $row['cell_phone'] . '</td>
  </tr>';
        }
    } else {
        $output = '
  <tr>
    <td colspan="4"> No result found. </td>   
  </tr>';
    }
    echo $output;
}
?>

I hope you get an idea about ajax live data search using jquery php mysql.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related posts:

  1. Ajax Live Data Search using Jquery PHP MySql
  2. how to fetch data from database in php mysql using search button?
  3. Autocomplete Search Box / textbox in PHP MySQL
Also Read This 👉   PHP Pagination demo – Pagination in PHP with example script
ajax live data search using jquery php mysql with paginationAjax live data search using PHP and MySQLajax live search jqueryajax live search with php and mysqlajax search box php mysql like googleglobal search in php mysql with examplesjquery ajax search examplephp mysql ajax search autocompletephp mysql search database and display results

Post navigation

Previous Post:Insert JSON data MySQL
Next Post:How To Print Last Query In PHP?

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (93) Education (63) Entertainment (130) fullform (87) Google Adsense (64) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1035) Mysqli (894) php (2133) Programming (2345) Python (99) Software (178) Software (90) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (147) Technology (2416) Tips and Tricks (130) Tools (214) Top10 (506) Trading (95) Trending (76) VueJs (250) Web Technology (113) webtools (200) wordpress (166) World (343)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites