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

时间:2018-04-27 06:26:06

标签: php warnings notice

如果我的数据库为空,则在我的localhost上显示警告和通知消息

$VM.Name, (($VM.VMId | Get-VHD | foreach{ [math]::round($_.size/1GB,1)}) -join " + ")

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:3)

如果没有行,您应该在加载前声明变量$rows

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

如果您不这样做,$rows只会在您while循环中设置。

您可以将此缩短为

$rows = mysqli_fetch_all ($tasks, MYSQLI_BOTH);

答案 1 :(得分:0)

只是对您当前代码的改进,因为上面的帖子已经回答了它。

<?php
    $rows = [];
    while ($row = mysqli_fetch_array($tasks)){ 
       if (isset($row)){
           $rows[] = $row;
       }
    }
?>                 
    Count is: <?= count($rows) ?> //You'll notice that I changed this line 
    //to a shorter version. since "<?= ?>" will automatically "echo" anything within 
    //it so you don't have to write echo and a closing ";"

      <?php
          foreach ($rows as $row_id  => $row){
          //let's clean your checkbox code here to make it more 
          //understandable
          $checked = ($row['status'])?"checked":"";//This is a ternary operator you can read [here][1]
          echo '<input type="checkbox" id="task" '.$checked.'>';
      ?>               
          <td class= "task"><?= $row['task'] ?></td>
    <?php } ?>

快乐编码