如何在自动填充中仅显示预定义的数组索引值?

时间:2015-07-29 15:05:19

标签: javascript php jquery

我的自动完成功能是通过从数据库中提取数据作为列表中的建议。但我对它做了一点修改。我希望以数组形式显示而不是显示字符串值。

请参考这个小提琴我使用的javascript:

http://jsfiddle.net/aLfpsn4y/

下面是我的php:

$my_data='$_GET["data"]';// this is the data user keys in
$sql="SELECT place,lat FROM loc_coordinate WHERE place LIKE '%$my_data%' ORDER BY place";
$result = mysqli_query($mysqli,$sql) or die(mysqli_error());
$test=array();
if ($result) {
    while ($row=mysqli_fetch_array($result)) {
        echo $row['place']." \n";//this is the name of the place shown in the autocomplete list
    }
}

显示如下:

existing autocomplete result

但我想改变它,如下所示(数组形式)

echo $row['place'].">".$row['lat']." \n ".//show two items in the array


Result of autocomplete

现在,当用户从自动填充列表中选择任何一项时,我只想选择$row['lat']

但它选择两者作为单个字符串:

Desired autocomplete result

如何让它只显示2.993518 //也许可以像$arrayName[1]

那样访问它

我认为需要在javascript文件中进行更改。

0 个答案:

没有答案