我的代码获取小于 255 的值,但如果列中的值大于 255,则不会返回。
<?php
include 'dbconfig.php';
$conn = new mysqli($servername, $username, $password, $dbname);
if($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM news ORDER BY id DESC";
$result = $conn->query($sql);
if($result->num_rows >0){
while($row[] = $result->fetch_assoc()) {
$tem = $row;
$json = json_encode($tem);
}
}else {
echo "0 results";
}
echo $json;
$conn->close();
?>
最佳答案
将代码更改为:
if($result->num_rows >0){
$json=[];
while(($row = $result->fetch_assoc())) {
$json[] = $row;
}
echo json_encode($json);
} else {
echo "0 results";
}
关于php - 使用php从mysql数据库中获取Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49589591/