2014-04-12 17 views
11

ile görüntüyü birleştirme, bu yüzden mysql veritabanından arama sonuçlarını görüntülemek için jQuery otomatik tamamlama özelliğini kullandığım bu projede çalışıyorum. Arama sonuçları, ürün görsellerine sahip bir veritabanından getirilen ürün adlarıdır. Ürün görsellerini aşağıdaki resimde nasıl görüntüleyebilirim? Kullanmak istediğiniz ediyorum _renderItem denilen bir yöntem varjQuery AutoComplete

<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'); 
} 

?> 

cevap

10

:

enter image description here

İşte benim jQuery otomatik tamamlama sayfadır. http://jsbin.com/cunuxaqe/2/edit

+1

bunun için bir açıklama verebilir misiniz:

İşte kullanımda bunun küçük demo? – NetStack

+0

Cevabımı bir demo ile güncelledim. –

+0

Kodunuzu gereksinimlerime göre düzenledim, ancak bu hatayı aldım. TypeError: $ products.data (...) undefined Söyleyebiliyor musunuz, olası sebep ne olabilir? – Moax6629

İlgili konular