2017-08-12 221 views
-1
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in ..php on line 21 

21号线布尔是警告:mysqli_num_rows()预计参数1被mysqli_result,给予

for ($i=0; $i < mysqli_num_rows($result); $i++) { 

代码:

$mysqli = connect(); 
      $MAX_SELECT = 50; 
      $SELECT_LIMIT_1 = 0+($MAX_SELECT*$page); 
      $result = $mysqli->query("SELECT alog.text, users.login, alog.userid from alog JOIN users ON alog.userid=users.id LIMIT ". $SELECT_LIMIT_1 .", ". $MAX_SELECT); 
      for ($i=0; $i < mysqli_num_rows($result); $i++) { 
       $rows = $result->fetch_assoc(); 
       if(isset($_GET['debug'])) print_r($rows); 
       echo ' 
       <tr> 
        <td><a href="/admin/user.php?id='. $rows["userid"] .'" style="color: #337ab7;">'. $rows["login"] .'</a>' .': '. $rows["text"] .'</td> 
       </tr> 
       '; 
      } 
      $mysqli->close(); 
+0

该错误意味着'$ mysqli-> query'失败并返回'false'而不是结果。之所以应该在'$ mysqli-> error' – apokryfos

+0

看看我的答案。可以帮你 – JYoThI

回答

0

你使用面向对象的风格mysqli

更改此信息

for ($i=0; $i < mysqli_num_rows($result); $i++) { 

for ($i=0; $i < $result->num_rows;; $i++) { 
+0

什么也没显示:( –

+0

也许你的查询不正确 – Ali

0

好像您的查询是行不通的。

确保您的查询已执行且$result有一些数据。

$mysqli = connect(); 
       $MAX_SELECT = 50; 
       $SELECT_LIMIT_1 = 0+($MAX_SELECT*$page); 
       $result = $mysqli->query("SELECT alog.text, users.login, alog.userid from alog JOIN users ON alog.userid=users.id LIMIT ". $SELECT_LIMIT_1 .", ". $MAX_SELECT); 
       if($result){ 
        for ($i=0; $i < mysqli_num_rows($result); $i++) { 
         $rows = $result->fetch_assoc(); 
         if(isset($_GET['debug'])) print_r($rows); 
         echo ' 
         <tr> 
          <td><a href="/admin/user.php?id='. $rows["userid"] .'" style="color: #337ab7;">'. $rows["login"] .'</a>' .': '. $rows["text"] .'</td> 
         </tr> 
         '; 
        } 
       }else{ 
        echo 'result Error'; 
       } 

       $mysqli->close(); 
+0

是啊,出错了,会检查。非常感谢! –

+0

让我知道它是否有效,并使问题完整。 –

0

1:object oriented style您执行的查询,并试图获得num_rows作为procedural style。你的mixing具有程序风格的面向对象风格

2nd:$mysqli->query(...)将返回True或False。所以做一个错误处理程序。

第3张:您可以像这样访问num_rows$result->num_rows查询成功后。

if(!$result){ 
    die($mysqli->error); 
}else{ 

     for ($i=0; $i < $result->num_rows; $i++) { 
      $rows = $result->fetch_assoc(); 
      if(isset($_GET['debug'])) print_r($rows); 
      echo ' 
      <tr> 
       <td><a href="/admin/user.php?id='. $rows["userid"] .'" style="color: #337ab7;">'. $rows["login"] .'</a>' .': '. $rows["text"] .'</td> 
      </tr> 
      '; 
     } 
} 
相关问题