我在使用PHP在Wordpress中填充一個Sql數組時出現問題。Jquery SQL Array Wordpress
我search.html
<form action="" method="post">
<input type="text" placeholder="Name" id="customerAutocomplte" class="ui-autocomplete-input" autocomplete="on" />
</form>
<script src="js/jquery.ui.autocomplete.html.js" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$.noConflict();
$(document).ready(function($){
$('#customerAutocomplte').autocomplete({
source:'suggest_name.php',
minLength:2
});
});
</script>
</head>
,這裏是suggest_name.php
/* Attempt MySQL server connection */
$link = mysqli_connect("localhost", "root", "mysql", "wordpress");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
else {
$link->set_charset('utf8');
}
/* retrieve the search term that autocomplete sends */
$term = trim(strip_tags($_GET['term']));
$a_json = array();
$a_json_row = array();
if ($data = $link->query("SELECT * FROM persons WHERE first_name LIKE '%$term%' OR last_name LIKE '%$term%' ORDER BY first_name , last_name")) {
while($row = mysqli_fetch_array($data)) {
$first_name = htmlentities(stripslashes($row['first_name ']));
$last_name = htmlentities(stripslashes($row['last_name']));
$code = htmlentities(stripslashes($row['customer_code']));
$a_json_row["id"] = $code;
$a_json_row["value"] = $first_name.' '.$last_name;
$a_json_row["label"] = $first_name.' '.$last_name;
array_push($a_json, $a_json_row);
}
}
// jQuery wants JSON data
echo json_encode($a_json);
flush();
我的SQL表
「人」
有4列
「FIRST_NAME」, 「姓氏」, 「電子郵件」 和 「customer_code」
「Customer_code」 是 「AI」 主鍵。我的問題是,搜索不會自動填充或填充數組,沒關係,sql數據庫包含條目,謝謝。