I want a searching like the one in Google. When you start typing there will be suggestions listed in a dropdown so I used autocomplete. My problem is when i type any key the output is "No result found" even though the data that I'm typing is in my database. I check my database connection and its right. Can someone explain to me what I'm doing wrong?
HTML
<input type="text" name="clientname" id="clientname" />
php This part is editted, i tried the suggestion of @asik but still not working
filename:getautocomplete.php
if (isset($_REQUEST['term'])){
$return_arr = array();
$stmt = $con->prepare('SELECT * FROM client WHERE CLIENTNAME LIKE :term');
$stmt->execute(array('term' => '%'.$_GET['term'].'%'));
while($row = mysqli_fetch_assoc($stmt)) {
$return_arr[] = $row['CLIENTNAME'];
}
echo json_encode($return_arr);
}
else
{
echo 'ERROR: ' . $e->getMessage();
}
JavaScript
$(function() {
$("#clientname" ).autocomplete({
source: "getautocomplete.php"
});
});
thanks in advance
try this, you are missing :
in named param
$stmt = $con->prepare('SELECT CLIENTNAME FROM client WHERE CLIENTNAME LIKE :term');
$stmt->execute(array(':term' => '%'.$_REQUEST['term'].'%'));
Hope this works, if not you can try formatting the response as label
& value
$return_arr[] = array('label' => $row['CLIENTNAME'], value => $row['CLIENTNAME']);
still not working post screenshot of getautocomplete.php
response using Firebug
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.