jquery ui autocomplete database
Posted
by user343925
on Stack Overflow
See other posts from Stack Overflow
or by user343925
Published on 2010-05-20T12:27:57Z
Indexed on
2010/05/20
12:30 UTC
Read the original article
Hit count: 475
Hello,
I'd like to use jQuery UI autocomplete in order to load a list from my database but I don't know wich method I should use to do so.
I tried to use the "Remote datasource" method [url]http://jqueryui.com/demos/autocomplete/#remote[/url], but it obviously doesn't work.
I have the following code :
js:
$(function() {
$("#client").autocomplete({
source: "nom.php",
minLength: 2,
select: function(event, ui) {
alert(ui);
}
});
});
html :
<label for="client">Client</label>
<input name="client" id="client" class="ui-autocomplete ui-widget-content ui-corner-all" />
php:
$query = "SELECT nom from personne";
$result = mysql_query($query, $db);
while($row = mysql_fetch_assoc($result)) {
foreach($row as $val)
$tab[] = $val;
}
print json_encode($tab);
It does work with ["hello","test1","test2"] instead of the url but I need to load datas form database so pls tell me how I should do.
thank you
© Stack Overflow or respective owner