2017-09-05 4 views
0

PHPを使用してWordpressでSql配列に値を設定する際に問題が発生しています。Jquery SQL配列ワードプレス

私はここで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"、 "LAST_NAME"、 "電子メール" および "customer_code"

は "Customer_code" は "AI" の主キーです。私の問題は、検索は自動入力や配列の入力ではなく、SQLデータベースにはエントリが含まれていることです。ありがとうございます。

答えて

0

documentationによれば、appendToセレクタを指定するか、入力にui-frontクラスの兄弟が必要です。

the same documentationによると、あなたのsourceArrayStringまたはFunction(Object request, Function response(Object data))のいずれかになります。あなたはそれらのどちらでもないPHPファイルを使用しています。これを行うには、PHPファイルとの間で情報を送受信できる関数を記述する必要があります。 AJAXはおそらく、非同期通信を可能にする(つまり、ページをリロードしてPHPに話す必要がない)ため、このようなスクリプトのための最良のオプションです。

これらの2つの問題だけでは、コードを破るのに十分です。私は別のものを見逃した可能性がありますが、私はこれらの2つのものを最初に修正することをお勧めします。

関連する問題