我正在使用以下 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);
但输出总是:
{"result":{"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null}}
这是您更新的代码应该是:
<?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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句