doudao2407 2018-04-27 06:26
浏览 196
已采纳

如果我的数据库为空,则显示警告

If my database is empty then showing the warning and notice messages on my localhost

         <?php
           while ($row = mysqli_fetch_array($tasks)){ 
              if (isset($row)){
                  $rows[] = $row;
              }
           }
          ?>                 
           Count is: <?php echo count($rows); ?>             
          <?php
              foreach ($rows as $row_id  => $row){
          ?>  

please help me to clear this problem.

  • 写回答

2条回答 默认 最新

  • douwen4401 2018-04-27 06:33
    关注

    You should declare the variable $rows before your load in case there are no rows.

       $rows = [];
       while ($row = mysqli_fetch_array($tasks))
       { 
          $rows[] = $row;
       }
    

    If you don't do this, $rows will only be set in your while loop as you've seen.

    You could shorten this to

    $rows = mysqli_fetch_all ($tasks, MYSQLI_BOTH);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?