Simple Google Suggestion Box Using jQuery

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Today, We Are Reading About Simple Google Suggestion Box Using jQuery

Project Name – Simple Google Suggestion Box Using jQuery+

Simple Google Suggestion Box Using jQuery


  • Database Name – ajaxtodo
  • Table Name – details
  • 4 Field – id(int, auto_increment, primary), name(varchar, 255), address(varchar, 255), phone(varchar, 255)


<!DOCTYPE html>
<html lang="en">

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Google Suggestion - By</title>
    <link rel="stylesheet" href="" />
    <link rel="stylesheet" href="style.css">

    <div class="container">
        <div class="row">
            <div class="col-md-12 d-flex flex-column justify-content-center align-items-center" style="height:100vh">
                <a href="" target="_blank"><img class="img-fluid mb-3" src="" alt=""></a>
                <div class="search-box">
                    <input class="form-control" type="text" name="search" id="search" placeholder="Enter Your Search Term" autocomplete="off">
                    <span class="suggestion" id="suggestion"></span>


    <!--add jquery-->
    <!--add bootstrap.js-->
    <!--add ajax.js file-->




    border-radius: 25px;
    padding:.75rem 1.25rem;

    border-color: #ddd;
    border-radius: 25px;
    border-radius: 0px 0px 25px 25px !important;
    background: #eee;
    margin-top: -5px; 



$conn = new mysqli('localhost', 'root', '', 'ajaxtodo');

if ($conn->connect_error) {
    die("Connection Failed");


//including db.php file for database connection
include 'db.php';

$search = $_POST['search'] ?? "";

//query for selecting data from our database
$query = "SELECT * FROM details WHERE name LIKE '%$search%'";

//execute query
$result = $conn->query($query);
$opt = "<ul class='list-unstyled list-group'>";
//checking result that should be more than 0
if ($result->num_rows > 0) {

    //looping our data till the last on our database
    while ($row = $result->fetch_assoc()) {
        $opt .= "<li class='list-group-item'>{$row['name']} - <span class='align-content-end'>{$row['address']}</li>";
} else {
    $opt .= "<li class='list-group-item'>No Result Found</li>";

$opt .= "</ul>";

echo $opt;

Now is the magic part – Ajax.js file

$(document).on('keyup', '#search', function () {
    let search = $(this).val();
    if (search.length > 3) {
            url: 'search.php',
            data: { search: search },
            method: "POST",
            success: function (res, text) {
                    borderRadius: "25px 25px 0px 0px",
                    borderBottom: "0px",
    } else {
            borderRadius: "25px",
            borderBottom: "1px solid #ddd",

This is only for learning purpose that you can understand easily. but you can make only one or two php file for making your project as small as possible. If you get any error or want to something new to learn share details below.

Other Important Topics


No comments yet. Why don’t you start the discussion?

Leave a Reply

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