1

php/mysql で jquery オートコンプリートを使用しています。オートコンプリートでデータベースから 3 つの値を取得したいと考えています。

$("#shipper_name").autocomplete({
    source: base_url + 'rainbowsoft/config/functions.php?shipper=shipper',
    focus: function(event, ui) {
        $("#shipper_name").val(ui.item.label);
        return false;
    },
    select: function(event, ui) {
        $("#shipper_name").val(ui.item.label);
        $("#shipper_details").val(ui.item.value);
        $("#client_id_shipper").val(ui.item.id);
        return false;
    }
});

ID を持つフィールド - client_id_shipper は、取得した ID を格納する必要がある隠しフィールドです。私のphp/mysqlは次を返します:

$data[] = array(
   'id'=>$row['id'],
   'label' => $row['client_name'],
   'value'=>$row['client_details'],
);
echo json_encode($data); 

ラベルと値が正しく表示されています.IDに関する問題があります.

4

0 に答える 0