I am newer to JSON and jQuery . I need to do a jQuery autocomplete, for this I put:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
jQuery(document).ready(function($){
$('#executives').autocomplete({source:'search_executives.php', minLength:2});
});
</script>
And in HTML :
<div class="rows">
<div class="labels">Search</div>
<div class="textboxs" style=" width: 175px;"><input id="executives" name="executive" /></div>
</div>
My search_executives.php is :
<?php
session_start();
if(empty($_SESSION['userid'])){
header('Location:index.php');
exit();
}
include_once('include/config.php');
$qry = "SELECT employee_id,fname,mname,lname FROM personal_details WHERE deg_id = '1'";
$res = $dbo->executeQuery( $qry ) ;
//$results[] = array('label' => $row['name']);
for( $i = 0; $i < count( $res ); $i++ )
{
$result[] = array( 'label' => $res[$i]['fname'].' '.$res[$i]['mname'].' '.$res[$i]['lname'] , 'value' => $res[$i]['employee_id'] ) ;
}
echo json_encode($result);
?>
Now my problem is -
- It outputs all the results, it does not depend on the search string I have entered.
- It prints the
value( e.g. 3 ) in the textfield in HTML. I need to print the name of the executives with hisemployee_idas his value.
NB: 1st Part is solved. I forgot to add the LIKE condition in SQL !