In this video you will learn How to make a autocomplete using jquery and php pdo with parsing json data from mysql
I am using the jquery easyautocomplete , link for this plugin http://easyautocomplete.com or click here
create mysql database autocomplete and create table autocomplete
Table structure:
id int value=12 , primary key autoincrement
title varchar=255 ,
json.php file
<html>
<head></he
<html>
<head>
<title>tutu</title>- <link rel="stylesheet" href="js/easy-autocomplete.min.css"/>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/jquery.easy-autocomplete.min.js"></script>
</head>
<body>
<h1>Auto complete plugin with php pdo and jquery</h1>- <input id="provider-json" />
<script type="text/javascript">
var options = {- url: "json.php",
- getValue: "jsondata",
list: {
match: {
enabled: true
}
}- };
$("#provider-json").easyAutocomplete(options);
</script>
</body- </html>
json.php file
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "autocomplete";
try{
$dbcon = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $ex){
die($ex->getMessage());
}- $sqlquery = "select * from autocomplete";
$run = $dbcon->prepare($sqlquery);- $run->execute();
- $out = array();
while($row=$run->fetch(PDO::FETCH_ASSOC)) {
$out[]= array('jsondata'=>$row['title']);
}
echo json_encode($out);
?>
No comments:
Post a Comment