i've used following code jquery autocomplete values database:
$( ".ui-widget" ).autocomplete({ source: "search.php", minlength: 2 });
search.php consists of following.
<?php $mysqli = new mysqli('localhost', 'airports2', '*******', 'airports2'); $text = $mysqli->real_escape_string($_get['term']); $query = "select airport airports airport '%$text%' order airport asc"; $result = $mysqli->query($query); $json = '['; $first = true; while($row = $result->fetch_assoc()) { if (!$first) { $json .= ','; } else { $first = false; } $json .= '{"value":"'.$row['name'].'"}'; } $json .= ']'; echo $json; ?>
when enter search term (which matches database entry), can see small whitespace, without results, didn't find any.
thanks lot in advance,
s.
try this
$result = $mysqli->query($query); $json = $result->fetch_all(mysqli_assoc); echo json_encode($json);
Comments
Post a Comment