【发布时间】:2012-11-01 00:28:57
【问题描述】:
我有一个来自 JQUERY 的自动完成功能,我想要的是产品的 ID,而不是我选择的产品的名称。
这是完整的自动完成:
<?php
// if the 'term' variable is not sent with the request, exit
if ( !isset($_REQUEST['term']) )
exit;
// connect to the database server and select the appropriate database for use
include 'conexion2.php';
// query the database table for client codes that match 'term'
$rs = mysql_query('SELECT id_cliente, nombrecliente FROM cliente where nombrecliente like "'. mysql_real_escape_string($_REQUEST['term']) .'%" order by nombrecliente asc', $conexio);
// loop through each name returned and format the response for jQuery
$data = array();
if ( $rs && mysql_num_rows($rs) )
{
while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
{
$data[] = array(
'label' => $row['nombrecliente'],
'value' => $row['nombrecliente'],
);
}
}
// jQuery wants JSON data
echo json_encode($data);
flush();
我在选择客户时不知道如何取出ID。如果我更改 'value' => $row['id_cliente'],那么我会在我的自动完成 INPUT 中获得 ID 号....
【问题讨论】:
-
'value' => $row['id_cliente'] ?
-
好的,我已经尝试过了,但它只是将客户端的 ID 放在自动完成的 INPUT 中。我想在自动完成的输入中看到客户端的名称,同时拥有客户端的 ID。
-
如果我没记错的话建议中包含 id 和 label...所以你必须切换然后...