php - 尝试在 while 循环之后创建 if 语句,或者在结果为空时执行其他操作。这可能吗?

标签 php if-statement is-empty

尝试在 while 循环之后创建 if 语句,以便在结果为空时执行其他操作。这可能吗?如果结果为空,我想显示不同的按钮。

<?php
while ($row = mysqli_fetch_array($result)){
?>

<tbody>
<form action = "create.php" method="POST">
<tr><td><input type="text" name="term" value="<?php echo $row['id']; ?>"       style="border: 0px solid #000000;" readonly></td>
<td><button type="submit" class="btn btn-primary" >Create</button> </td>
</form>
</tr><td><button type="back" class="btn btn-primary" onClick="location.href='index.php'" >Back</button> </td>
<td></td>
</form><tr>
</tr>
</tbody>

<?php
};
?>

最佳答案

试试这个

$row_count = mysqli_num_rows($result);
if($row_count == 0){
?>
    <tbody>
    <form action = "create.php" method="POST">
    <tr><td><input type="text" name="term" value="<?php echo $row['id']; ?>"       style="border: 0px solid #000000;" readonly></td>
    <td><button type="submit" class="btn btn-primary" >Create</button> </td>
    </form>
    </tr><td><button type="back" class="btn btn-primary" onClick="location.href='index.php'" >Back</button> </td>
    <td></td>
    </form><tr>
    </tr>
    </tbody>
<?php
}
else
{
    <?php
    while ($row = mysqli_fetch_array($result)){


    //Do your action



    ?>

    <?php
    }
}
?>

关于php - 尝试在 while 循环之后创建 if 语句,或者在结果为空时执行其他操作。这可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24780029/

相关文章:

ant - 如果满足两个条件,则执行 Ant 任务

java - ArrayList 删除错误

php - 代码正确时在mysql中出现错误

java - OOP 票价计划

c++ - 为什么这个 IF 语句不在循环内打印

arrays - 数组中的数组/字典是空快捷方式

php - 为自定义功能扩展 phpdocumentor2

php - 优化多数据库 Web 应用程序的正确方法

PHP 脚本在提交时返回 "undefined"

C if else 循环不起作用