Crewow is a Blog contains Free Web Training's, Tutorials, Resources and much more. It will feature best Tutorials related Jquery, PHP, Ajax, CSS and other Web development languages. It will also tell you the sites from where you can get best web resources. Creatively Wow!
Friday, 18 October 2013
PHP-MySQL Ajax Jquery-UI Autocomplete in Bootstrap Tutorial
This tutorial will show you how to use Jquery UI Autocomplete in Bootsrap via PHP, MySQL and AJAX. You can use it anywhere else too easily.
You will learn to make Jquery UI autocomplete working in Bootstrap via PHP, MySQL and Ajax.
First create a simple form using below code or you can use your own search code. Please note id of input is searchg which will use later.
Now on Get_Categories.php page you will write following code to get results from database and output JSON String.
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = 'username';
/*** mysql password ***/
$password = 'password';
// Database Connection
$dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
// Query to get the usable locations
$locale = $_GET['term'];
$sql = "SELECT DISTINCT Category FROM `category` WHERE `Category` LIKE '%$locale%'";
// Deifne array for products
$Product_array = array();
foreach ($dbh->query($sql) as $row)
$result = $row;
// use arrray_push to store results
// put files in $jason and then echo it for getting in your page using Ajax.
$json = json_encode($Product_array);
Below is a code for MySQL Table, you can copy it and paste it in your query window inside database.