好的,我在使用 JQuery 自动完成时遇到问题。
在搜索栏中,当我开始输入时,它只显示来自 searchfrnds.php 的名字。我想要的是它应该以某种方式连接 searchfrnds.php 的结果,使其在显示的搜索结果下拉列表中显示名字和姓氏。
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代码:
<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>