【发布时间】:2011-10-21 21:40:30
【问题描述】:
好的,所以我将使用 JQuery 进入下一个阶段,并且我已经成功使用了几次 AutoComplete,但只使用了 MYSQL 中的 1 个表。现在我正在使用它并尝试使用它进行 JOIN 查询。当我在 MYSQL 中将LIKE :term 更改为= 1(例如客户编号)时,MYSQL 查询工作正常,但是当我尝试下面的查询时,我什么也没得到,不是错误,什么也没有。有什么建议吗?
::: 这是搜索页面 :::
<?php require '../_includes/jq.inc.php';?>
<link href="../_stylesheets/UPDATE.Customer.css" rel="stylesheet" type="text/css">
<html>
<head>
<script type="text/javascript">
$(function() {
$('#CustomersCustomer_ID').val("");
$('#CustomersCompanyName').val("");
$('#CustomerDetailsDiscount').val("");
$('#CustomerNotesCustNotes').val("");
$("#searchterm").autocomplete({
source: "UPDATE.Customer.SEARCH.QUERYTEST.php",
minLength: 1,
select: function(event, ui) {
$('#CustomersCustomer_ID').val(ui.item.CustomersCustomer_ID);
$('#CustomersCompanyName').val(ui.item.CustomersCompanyName);
$('#CustomerDetailsDiscount').val(ui.item.CustomerDetailsDiscount);
$('#CustomerNotesCustNotes').val(ui.item.CustomerNotesCustNotes);
}
});
});
</script>
</head>
<body>
<form action="<?php echo $PHP_SELF;?>" method="post">
SEARCH:<p class="ui-widget">
<input type="text" id="searchterm" size="60" onClick="this.form.reset()"/>
</form>
<form>
CustomersCustomer_ID<br>
<input name="CustomersCustomer_ID" type="text" id="CustomersCustomer_ID" size="10">
<br>
CustomersCompanyName<br>
<input name="CustomersCompanyName" type="text" id="CustomersCompanyName" size="20">
<br>
CustomerNotesCustNotes<br>
<textarea name="CustomerNotesCustNotes" id="CustomerNotesCustNotes" cols="20" rows="3"></textarea>
<br>
CustomerDetailsDiscount<br>
<input name="CustomerDetailsDiscount" type="text" id="CustomerDetailsDiscount" size="5">
</form>
</body>
</html>
这是后端查询页面 // 遗漏了连接信息
if ($conn)
{
$ac_term = "%".$_GET['term']."%";
$query = "SELECT
Customers.Customer_ID,
Customers.CompanyName,
CustomerDetails.Discount,
CustomerNotes.CustNotes,
CONCAT_WS(' ', Customers.Customer_ID, Customers.CompanyName, CustomerDetails.Discount, CustomerNotes.CustNotes) AS DisplayName
FROM Customers
JOIN CustomerDetails USING (`Customer_ID`)
JOIN CustomerNotes USING (`Customer_ID`)
WHERE `Customer_ID` LIKE :term
OR Customers.CompanyName LIKE :term
OR CustomerDetails.Discount LIKE :term
OR CustomerNotes.CustNotes LIKE :term
";
$result = $conn->prepare($query);
$result->bindValue(":term",$ac_term);
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$row_array['value'] = $row['DisplayName'];
$row_array['CustomersCustomer_ID'] = $row['Customers.Customer_ID'];
$row_array['CustomersCompanyName'] = $row['Customers.CompanyName'];
$row_array['CustomerDetailsDiscount'] = $row['CustomerDetails.Discount'];
$row_array['CustomerNotesCustNotes'] = $row['CustomerNotes.CustNotes'];
array_push($return_arr,$row_array);
}
}
$conn = null;
echo json_encode($return_arr);
?>
【问题讨论】:
标签: php jquery mysql autocomplete