私は JSON と jQuery に慣れていません。jQuery オートコンプリートを実行する必要があるため、次のようにします。
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
jQuery(document).ready(function($){
$('#executives').autocomplete({source:'search_executives.php', minLength:2});
});
</script>
そしてHTMLで:
<div class="rows">
<div class="labels">Search</div>
<div class="textboxs" style=" width: 175px;"><input id="executives" name="executive" /></div>
</div>
私search_executives.php
は:
<?php
session_start();
if(empty($_SESSION['userid'])){
header('Location:index.php');
exit();
}
include_once('include/config.php');
$qry = "SELECT employee_id,fname,mname,lname FROM personal_details WHERE deg_id = '1'";
$res = $dbo->executeQuery( $qry ) ;
//$results[] = array('label' => $row['name']);
for( $i = 0; $i < count( $res ); $i++ )
{
$result[] = array( 'label' => $res[$i]['fname'].' '.$res[$i]['mname'].' '.$res[$i]['lname'] , 'value' => $res[$i]['employee_id'] ) ;
}
echo json_encode($result);
?>
今私の問題は -
- 入力した検索文字列に依存せず、すべての結果を出力します。
value
HTMLのテキストフィールドに(例 3 )を出力します。幹部の名前をemployee_id
彼の値として出力する必要があります。
注意: 第 1 部は解決済みです。LIKE
に条件を追加するのを忘れていましたSQL
。