Reputation: 543
I have mysql database and I have table from which I need to take entire row. Than I need to put that row in jquery ui autocomplete so I can call it with my input field. Problem is that I made array with all items from row but they need to be separated in jquery. So it can't be like this:
[
{"Location":"Zagreb"},
{"Location":"Split"},
{"Location":"Zadar"},
{"Location":"Zlatar"},
{"Location":"Osijek"}
]
but it has to be like:
"Split", "Zadar", "Zlatar", "Osijek"
So my php:
$query = 'SELECT Location FROM locations';
$result = mysqli_query ($link, $query);
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$rows[] = $r;
}
echo json_encode($rows);
And jquery autocomplete:
$( "#location1" ).autocomplete({
source: [ '<?php echo json_encode($rows);
?>' ]
});
Some tips?
Upvotes: 0
Views: 206
Reputation: 2489
After your query you are appending each row array to $rows. You only want to append the value for the column Location:
$query = 'SELECT Location FROM locations';
$result = mysqli_query($link, $query);
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$rows[] = $r['Location'];
}
Upvotes: 1