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,但它沒有奏效。 –
你可以發佈該查詢嗎? –