Creating Autocomplete & Search Suggestion Functionality with PHP and MySQL

Hello Mates,

We all know that most of the websites have user-friendly search features. Various search features can be implemented to make a site more user compatible, where users can interact with the whole site easily.Today we will learn to create Autocomplete & Search Suggestion Functionality.in this tutorial we will create a function which will predict a user query or try to compose the right question from our site so that we can easily understand the requirement of the user. The best solution for building the user-friendly search features are with autocomplete or search suggested keywords from the database to get the better response from the server.

For adding such functionality to our site a few year ago, you need expertise in several technologies like Ajax, jQuery, CSS, PHP, MYSQL etc.

But today, we can use the library of the twitter’s Typehead.js library, a jQuery plugin designed for add autocomplete functionality into your search boxes.

For the knowledge of our fellow mates typehead.js doesn’t hold any sample with an MYSQL database.
Let’s learn how to create autocomplete & advance search suggestions with PHP and MYSQL.

Firstly, let’s create an index.php file
[cc-code]

PHP MySQL Typeahead Autocomplete



 

Put your keyword here for search

 

[/cc]

Now, we will create a city.php file which will fetch all the result from MYSQL database and return the response in the JSON format. Here is the city.php code:

[cc-code]
‘value’ => $row[‘city’],
);
}
//RETURN JSON ARRAY
echo json_encode ($array);
}
?>

[/cc]

Here is the source file for our fellow mates to try. Download Here
Now, Let’s try the name of the cities like Delhi etc to get the result as a suggested city.
We hope this tutorial is helpful for you guys!

You can also visit our other trending topics:

ANIMATED AJAX RECORD DELETION USING JQUERY PHP

GENERATE QR CODE WITH PHP USING GOOGLE CHART API

CODEIGNITER GEOLOCATION LIBRARY

Guys feel free to share your problems with us, comment or mail us at phphurdle@gmail.com.You can also share your experiences in our new section write for us where you can write your own tutorials and can help your fellows.
Because Hurdles aren’t really Hurdles.

Be First to Comment

Leave a Reply

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