Reputation: 536
OK i am having trouble with JQuery autocomplete.
In search bar when i start typing it just shows firstname from searchfrnds.php. What i want is that it should somehow concatenate the result from searchfrnds.php in such a way that it shows firstname as well as lastname in the search result drop down that displays.
Code for searchfrnds.php:
<?php
$term = trim(strip_tags($_GET['term']));
$query = "SELECT aid,firstname, lastname, profpic,email,abtyou
FROM artist92 WHERE firstname LIKE '%".$term."%' OR lastname LIKE '%".$term."%'";
$result = mysqli_query ($link, $query);
$array = array();
while($obj = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$array['value'] = $obj['firstname'];
$array['lvalue'] = $obj['lastname'];
$array['icon'] = $obj['profpic'];
$array['aid']=$obj['aid'];
$array['abt']=$obj['abtyou'];
$array['email']=$obj['email'];
$row_set[]=$array;
}
echo json_encode($row_set);
?>
JQuery code :
<script>
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#frndsrch" ).autocomplete({
source: "searchfrnds.php",
minLength: 2,
select: function( event, ui ) {
$( "#project-icon" ).attr( "src", "" + ui.item.icon );
$('a').attr('href',"viewartprofile.php?aid=" + ui.item.aid );
}
});
});
</script>
Upvotes: 0
Views: 904
Reputation: 36244
jquery ui autocomplete's item's label
is showed (& searched by default) and value
is inserted if the option is selected - if one is ommitted, other's value is copied & used.
Upvotes: 0
Reputation: 905
Assuming jQueryUI autocomplete is displaying the value part of the array, just do:
$array['value'] = $obj['firstname'].' '.$obj['lastname'];
And then that should display both as required.
Upvotes: 2