如果我的数据库为空,则在我的localhost上显示警告和通知消息
$VM.Name, (($VM.VMId | Get-VHD | foreach{ [math]::round($_.size/1GB,1)}) -join " + ")
请帮我解决这个问题。
答案 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 } ?>
快乐编码