PHP query data has no results
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-24 11:31:07
0
2
623

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);
曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
習慣沉默

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 endlessly

滿天的星座

Not to mention anything else, this loop breaks directly, making it impossible to assign a value to $output.

 while(true){
    if($row){
      break;
    }
    $output[]=$row;
 }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template