so I'm working on this project where I'm using jQuery autoplete to display search results from a mysql database. The search results are product names fetched from a database which has product images as well. How would I be able to display the product images like in the image below ?
Here's my jQuery auto plete page :
<script>
$( "#birds" ).autoplete({
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');
}
?>
so I'm working on this project where I'm using jQuery autoplete to display search results from a mysql database. The search results are product names fetched from a database which has product images as well. How would I be able to display the product images like in the image below ?
Here's my jQuery auto plete page :
<script>
$( "#birds" ).autoplete({
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');
}
?>
Share
Improve this question
edited Apr 17, 2015 at 13:47
Bill Criswell
32.9k8 gold badges79 silver badges67 bronze badges
asked Apr 12, 2014 at 18:57
NetStackNetStack
2082 gold badges3 silver badges11 bronze badges
1 Answer
Reset to default 13There's a method called _renderItem
that you'd want to use.
Here's a small demo of it in use: http://jsbin./cunuxaqe/2/edit