我的自动完成功能是通过从数据库中提取数据作为列表中的建议。但我对它做了一点修改。我希望以数组形式显示而不是显示字符串值。
请参考这个小提琴我使用的javascript:
下面是我的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
}
}
显示如下:
但我想改变它,如下所示(数组形式)
echo $row['place'].">".$row['lat']." \n ".//show two items in the array
现在,当用户从自动填充列表中选择任何一项时,我只想选择$row['lat']
。
但它选择两者作为单个字符串:
如何让它只显示2.993518 //也许可以像$arrayName[1]
我认为需要在javascript文件中进行更改。