11
그래서이 프로젝트에서 저는 jQuery 자동 완성을 사용하여 mysql 데이터베이스의 검색 결과를 표시하고 있습니다. 검색 결과는 제품 이미지가있는 데이터베이스에서 가져온 제품 이름입니다. 아래 그림과 같이 제품 이미지를 어떻게 표시 할 수 있습니까? 사용하려는 것 _renderItem
라는 방법이있다jQuery 자동 완성과 이미지 통합
<script>
$("#birds").autocomplete({
source: "search.php",
minLength: 2,
select: function(event, ui) {
log(ui.item ? "Selected: " + ui.item.value + " aka " + ui.item.label :
"Nothing selected, input was " + this.actor);
window.location.href = './products/' + ui.item.productid;
//window.location.href = 'product_display.php?id=' + ui.item.value;
// document.testForm.action = "pretravel.php?id="+ui.item.value;
//document.testForm.submit();
}
});
});
</script>
search.php
<?php
include 'dbconnector.php';
// Sanitise GET var
if(isset($_GET['term']))
{
$term = mysql_real_escape_string($_GET['term']);
// Add WHERE clause
//$term="Apple";
$query = "SELECT `productid`, `productname` FROM `products` WHERE `productname` LIKE '%".$term."%' ORDER BY `productid`";
$result = mysql_query($query,$db) or die (mysql_error($db));
$id=0;
$return=array();
while($row = mysql_fetch_array($result)){
//array_push($return,array('label'=>$row['productid'],'actor'=>$row['productname']));
//array_push($return,array('value'=>$row['productid'],'label'=>$row['productname']));
//array_push($return,array('actor'=>$row['productname'],'label'=>$row['productid']));
array_push($return,array('productid'=>$row['productid'],'label'=>$row['productname']));
}
header('Content-type: application/json');
echo json_encode($return);
//var_dump($return);
exit(); // AJAX call, we don't want anything carrying on here
}
else
{
header('Location:index');
}
?>
당신이 그것에 대해 설명을 전해 주 시겠어요 :
여기에 사용 그것의 작은 데모입니까? – NetStack
답변을 데모로 업데이트했습니다. –
내 필요에 따라 코드를 편집했지만이 오류가 발생했습니다. TypeError : $ products.data (...)가 정의되지 않았습니다. 가능한 이유가 무엇인지 말해 줄 수 있습니까? – Moax6629