Weird problem. The code that worked well before suddenly failed to produce results today. I used SQL statements to check the database and could find it. I don’t know where the problem lies. The PHP version number is 5.2.0.
code show as below:
<?php
header("content-Type:application/json");
$conn=mysqli_connect("127.0.0.1",'root','','ecwng',3306);
$sql="SET NAMES UTF8";
mysqli_query($conn,$sql);
$count=5;
@$start=$_REQUEST['start'];
if(empty($start)){
$start=0;
}
//require('init.php');
$sql="SELECT * FROM ecwng_dish";
//LIMIT $start,$count
$result=mysqli_query($conn,$sql);
var_dump($result);
$output=[];
if($result){
$row=mysqli_fetch_assoc($result);
while(true){
if($row){
break;
}
$output[]=$row;
}
}
echo json_encode($output);
The first problem is as mentioned above, the problem of conditional judgment of break; the second problem is that
$row=mysqli_fetch_assoc($result)
should be placed in the brackets after while. Otherwise, if there is no result, break directly; if there is a result, it will loop endlesslyNot to mention anything else, this loop breaks directly, making it impossible to assign a value to $output.