search

Home  >  Q&A  >  body text

PHP query data has no results

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

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-05-24 11:33:07

    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

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-24 11:33:07

    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;
     }

    reply
    0
  • Cancelreply