I’m trying to get an autocomplete working for a website I’m building for my company, but I can’t seem to get the jQuery function to execute. The website is build on top of WordPress.
The input line:
<strong>Customer: </strong> <input type='text' name='cust' id='cust'>
The autocomplete:
<script type='text/javascript'>
jQuery('#cust').autocomplete({
source : "Scripts/cust_search.php",
minLength:1
});
And cust_search.php:
<?
$term = trim(strip_tags($_GET[ "term" ]));
$a_json = array ();
$a_json_row = array ();
if ($companies = $panther->get_results("SELECT Cust_ID, Cust_Name FROM Customer LIKE '%$term%' ORDER BY Cust_Name ASC;")) {
while ($row = mysqli_fetch_array($companies)) {
$a_json_row ["id"]=$panther->escape($row['Cust_ID']);
$a_json_row ["value"]=$panther->escape($row['Cust_Name']);
$a_json_row ["label"]=$panther->escape($row['Cust_Name']);
array_push($a_json, $a_json_row);
}
}
echo json_encode( $a_json );
?>
The problem it seems to be your sql query.
You are missing WHERE statement
try
instead: