0
我已经为我的网络实现了jQuery自动完成功能,它工作正常。但是我希望自动完成的结果仅检索特定人员的数据,而不是完整的数据库结果。jQuery自动完成从数据库中检索数据
下面是jQuery的用于自动完成
jQuery(document).ready(function($){
$('.product_desc').autocomplete({source:'functions/products.php?', minLength:2});
products.php
//Path for the databsae
<?php
include '../include/configuration.php';
if (!isset($_REQUEST['term']))
exit;
$rs = mysql_query('select id,item_name,fk_vendor_id from item where item_name like "%'. mysql_real_escape_string($_REQUEST['term']).'%" order by item_name asc ', $con);
$data = array();
if ($rs && mysql_num_rows($rs))
{
while($row = mysql_fetch_array($rs, MYSQL_ASSOC))
{
$data[] = array(
'label' => $row['item_name'],
'value' => $row['item_name']
);
}
}
else
{
$data[] = array(
'label' => 'not found',
'value' =>''
);
}
// jQuery wants JSON data
echo json_encode($data);
flush();
?>
任何解决方案将受到赞赏。
如果您想要一条记录,请在查询中设置LIMIT 1或在查询中传递用户ID。 –
嗨Ravi,我试着传递用户ID,但它没有奏效。 –
你可以发布该查询吗? –