我使用以下PHP代码从数据库中检索商店信息字段,但是当我运行PHP时,我得到了如下所示的错误。
<?php
include ('database.php');
$locLat ;
$locLng ;
$shopName;
$shopContact;
$sql = "SELECT s_iD, s_name,s_contNo,s_lat,s_long from tbl_shop";
$result = mysqli_query($con,$sql);
$arrayResult = array();
while ($row = mysqli_fetch_array($result)){
array_push($arrayResult,array("id"=>$row['s_iD'],"shopName"=>$row['s_name'],"shopContact"=>$row['s_contNo'],"latitude"=>$row['s_lat'],
"longitude"=>$row['s_long']));
}
echo json_encode (array('result'=> $result));
mysqli_close($con);
但输出总是:
{ “结果”:{ “current_field”:NULL, “场计数”:NULL, “长度”:NULL, “NUM_ROWS”:空, “类型”:空}}
答案 0 :(得分:1)
这里更新的代码应该是:
<?php
include ('database.php');
$locLat ;
$locLng ;
$shopName;
$shopContact;
$sql = "SELECT s_iD, s_name,s_contNo,s_lat,s_long from tbl_shop";
$result = mysqli_query($con,$sql);
$arrayResult = array();
while ($row = mysqli_fetch_array($result)){
array_push($arrayResult,array("id"=>$row['s_iD'],"shopName"=>$row['s_name'],"shopContact"=>$row['s_contNo'],"latitude"=>$row['s_lat'],
"longitude"=>$row['s_long']));
}
echo json_encode (array('result'=> $arrayResult)); // <-- changed from $result
mysqli_close($con);