Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
!空PHP函数不适用于SQL查询_Php_Sql - Fatal编程技术网

!空PHP函数不适用于SQL查询

!空PHP函数不适用于SQL查询,php,sql,Php,Sql,如果我用这个!在sql查询中为空,即使没有返回任何行,也不会说它为空。e、 g $result = $conn->query($sql_ideas); if ( !empty($result)) { while($row = $result->fetch_assoc()) { $highlights[] = array($row["summary"], $row["detail"]); } -- Do stuff -- } 它只是像返回结果一样进行。我是做错了什么还是

如果我用这个!在sql查询中为空,即使没有返回任何行,也不会说它为空。e、 g

$result = $conn->query($sql_ideas);
if ( !empty($result)) {
  while($row = $result->fetch_assoc()) {
  $highlights[] = array($row["summary"], $row["detail"]);
}   
-- Do stuff --
}

它只是像返回结果一样进行。我是做错了什么还是有办法解决这个问题?

假设您使用的是mysqli,那么您的结果对象实际上就是一个“mysqli result”——一个本身就属于它的类。检查行计数是否大于零将是一种方法


为什么你甚至需要检查?因为如果查询返回值,我想完成一些HTML,如果它不转到下一个查询…@StuartDurning这就是行计数方便的地方。谢谢!虽然我很明显很愚蠢。。。。但是为什么这个错误不。。。如果mysql\u num\u rows$result>0或此``$num_rows=mysql_num_rows$result;如果$num_rows>0{…说'mysql_num_rows期望参数1是一个资源'**前面的评论是为了说明为什么会出现这个错误。我只需要把它放在我的fetch_assoc语句之后。谢谢!