I have jQuery UI autocomplete input with AJAX source where I want to show the label and not the id; but my code shows both when the search results come back. How can I show just the label?
PHP:
<?php
require_once '../php/db_conx.php';
$req = "SELECT *
FROM ads
WHERE bbookname LIKE '%" . strtolower(mysql_real_escape_string($_REQUEST['term'])) . "%' ";
$query = mysql_query($req);
while ($row = mysql_fetch_array($query)) {
$return = array(
'label' => $row['bbookname'] . ' ' . $row['bbookschool'],
'value' => $row['adid']
);
}
echo json_encode($return);
?>
jQuery/AJAX:
$("#BooksSearchInput").autocomplete({
source: '../Search/BP_Books_Search.php',
minLength: 1,
autoFocus: false,
select: function(event, ui) {
var SearchBookVal = (ui.item.value)
$.ajax({
type: "POST",
data: {
data: SearchBookVal
},
url: "../php/SearchBooks_results.php"
}).done(function(feedback) {
$('#booksads').html(feedback)
});
}
});
Please note that I do need the adid
to be available in the JavaScript callback, as I use this to reference the result.