首页 > 解决方案 > 我的代码没有在前端显示数据库值。谁能帮我?

问题描述

我试图用 id 显示我的数据库表的名称,但它不起作用。谁能帮我解决问题在哪里?
它说成功添加了类别中的数据,但上面的代码无法在表格中显示。

代码

<table class="table table-hover">
    <tr>
    <th>Sr No.</th>
    <th>Category Name</th>
    </tr>
    <? php 
        global $connectiondb;
        $ViewQuery="SELECT * FROM category";
        $Execute=mysqli_query($connection, $ViewQuery);
        $SrNo=0;
        while ($DataRows=mysqli_fetch_array($Execute,MYSQLI_BOTH);) {
            $Id=$DataRows["id"];
            $CategoryName=$DataRows["name"];
            $SrNo++;
        ?>
    <tr>
        <td><? php echo $Id; ?></td>
        <td><? php echo $CategoryName; ?></td>
    </tr>
    <? php } ?>

标签: phpdatabasemysqli

解决方案


尝试显示 SrNo 视图是否大于 0。如果 SrNo 大于 0,则意味着要显示的数据。请试试我的这段代码,看看它对你有没有帮助:

<table class="table table-hover">
    <tr>
        <th>Sr No.</th>
        <th>Category Name</th>
    </tr>
    <?php 
   global $connectiondb;
        $ViewQuery="SELECT * FROM category";
        $Execute=mysqli_query($connection, $ViewQuery);
        $SrNo=0;
    while($DataRows=mysqli_fetch_assoc($Execute)) {
        $Id=$DataRows["id"];
        $CategoryName=$DataRows["name"];
        $SrNo++;
    ?>
    <tr>
        <td><?php echo $Id; ?></td>
        <td><?php echo $CategoryName; ?></td>
    </tr>
    <?php } ?>
</table>

推荐阅读