我的数据库数据显示不好

pgx2nnw8  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(357)

我想从用户数据库中选择我的所有用户。。代码可以工作,但我想我错过了一些关于我的语法和我如何呼应它。。。所以它实际上检索它们,但是它为每个数据生成不同的表。。。。
我附上了照片

<?php
            // seclect users from table
            $selectUsers = "SELECT * FROM users ORDER BY userId DESC";
            $selectUserKwery = mysqli_query($link, $selectUsers);
            $userCount = mysqli_num_rows($selectUserKwery);
            if($userCount > 0){
            while ($userRow = mysqli_fetch_array($selectUserKwery)) { ?>
            <div class="table-responsive">
              <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                <thead>
                  <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Join Date</th>
                    <th>ACTION</th>
                  </tr>
                </thead>
                <tfoot>
                  <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Join Date</th>
                    <th>ACTION</th>
                  </tr>
                </tfoot>
                <tbody>
                  <tr>
                    <td><?php echo ucwords($userRow['userId']); ?></td>
                    <td><?php echo ucwords($userRow['userName']); ?></td>
                    <td>Edinburgh</td>
                    <td>61</td>
                    <td><p><a><i class="fa fa-fw fa-eye"></i></a> | <a><i class="fa fa-fw fa-edit"></i></a> | <a><i class="fa fa-fw fa-user-times"></i> </a> </p></td>
                  </tr>
                </tbody>
              </table>
                <?php     

            }
            } else if($userCount > 0) {
                        echo '<div class"alert alert-danger alert-dismissable">There are no Users yet</div>';
                } ?>


所以我希望数据库结果显示在一个表中
新结果

w3nuxt5m

w3nuxt5m1#

你得到了多张table因为你的 <table> 是在 while . 您应该将表的结构元素移到 while 只需在 while . 像这样的

?>
            <div class="table-responsive">
              <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                <thead>
                  <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Join Date</th>
                    <th>ACTION</th>
                  </tr>
                </thead>
                <tfoot>
                  <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Join Date</th>
                    <th>ACTION</th>
                  </tr>
                </tfoot>
                <tbody>
<?php while ($userRow = mysqli_fetch_array($selectUserKwery)) { ?>
                  <tr>
                    <td><?php echo ucwords($userRow['userId']); ?></td>
                    <td><?php echo ucwords($userRow['userName']); ?></td>
                    <td>Edinburgh</td>
                    <td>61</td>
                    <td><p><a><i class="fa fa-fw fa-eye"></i></a> | <a><i class="fa fa-fw fa-edit"></i></a> | <a><i class="fa fa-fw fa-user-times"></i> </a> </p></td>
                  </tr>
<?php }/* close while */ ?>
                </tbody>
              </table>

我应该这么做。在构建 <table> .

相关问题