[英]PHP JSON not displaying MySQL result
The PHP I created retrieve data from a MySQL database and turns it into a JSON which is then echoed. 我创建的PHP从MySQL数据库检索数据,并将其转换为JSON,然后将其回显。 I had 300 records and the PHP was able to display the JSON and was visible when viewed.
我有300条记录,PHP能够显示JSON,并且在查看时可见。
However, I added another 100 records to the same table and for some reason the JSON isn't being displayed. 但是,我在同一张表中又添加了100条记录,由于某种原因,没有显示JSON。 It just appears blank with no error.
它只是显示为空白,没有错误。 But when I remove the 100 records, the JSON displays as normal.
但是,当我删除100条记录时,JSON会正常显示。
I haven't touched the PHP file during this. 在此期间,我没有触摸过PHP文件。 What could the reason be?
原因可能是什么?
<?PHP
include_once("connection.php");
$query = "select id,mosque_name,latitude,longitude from mosques;";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
$response["mosques"] = array();
while ($row = mysqli_fetch_array($result)) {
$mosque = array();
$mosque["id"] = $row["id"];
$mosque["mosque_name"] = $row["mosque_name"];
$mosque["latitude"] = $row["latitude"];
$mosque["longitude"] = $row["longitude"];
array_push($response["mosques"], $mosque);
}
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "No mosques found";
echo json_encode($response);
}
?>
Try This:- 尝试这个:-
<?PHP
include_once("connection.php");
$query = "select id,mosque_name,latitude,longitude from mosques;";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) == 0) {
echo json_encode("");
}
else{
while ($row = mysqli_fetch_array($result)) {
/*$mosque = array();
$mosque["id"] = $row["id"];
$mosque["mosque_name"] = $row["mosque_name"];
$mosque["latitude"] = $row["latitude"];
$mosque["longitude"] = $row["longitude"];*/
$fetchRow[]=$row;
// array_push($response["mosques"], $mosque);
}
echo json_encode($fetchRow);
}
/* $response["success"] = 1;
echoing JSON response
echo json_encode($response);*/
?>
and check your result from network 并检查网络结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.