【问题标题】:My table is not populating correctly我的表格没有正确填充
【发布时间】:2014-05-18 18:59:22
【问题描述】:

我试图从我的 MYSQL 表中获取所有内容,然后将它们全部放入一个表中。出于某种原因,它会将所有数据都放在一行中,而不是为更多数据创建新行。

我的代码在这里:

 <?php
        //DISPLAY CURRENT USERS ASC ON VIEW
        $q="SELECT * FROM users ORDER BY id ASC";
        $r=mysqli_query($dbc,$q);

        ?>

<div class="panel panel-default">
  <!-- Default panel contents -->
  <div class="panel-heading">User Manager</div>
  <div class="panel-body">
    <p>Some default panel content here. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
  </div>

  <!-- Table -->
<div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>UserID</th>
                  <th>First Name</th>
                  <th>Last Name</th>
                  <th>Email</th>
                  <th>Status</th>
                  <th>Role</th>
                </tr>
              </thead>
              <tbody>
                <?php  echo "<tr>"; // Display Users onto table
    while (($list= mysqli_fetch_assoc($r))){
            echo"<td>".$list['id']."</td>";
            echo"<td>".$list['fname']."</td>";
            echo"<td>".$list['lname']."</td>";
            echo"<td>".$list['email']."</td>";
            echo"<td>".$list['status']."</td>";
            echo"<td>".$list['role']."</td>";

    }
                echo"</tr>";?>       

              </tbody>
            </table>
          </div>

</div>

【问题讨论】:

  • 标签(即行标签)也应该在循环中。
  • 并在循环外取出&lt;tr&gt;&lt;/tr&gt;
  • 感谢所有修复它的人。很抱歉延迟了一段时间远离编码。感谢您的所有帮助!

标签: php mysqli html-table


【解决方案1】:

所有TR 标签都在循环之外。

【讨论】:

  • 哇!愚蠢的错误。谢谢 Benio,你太棒了!
【解决方案2】:

似乎在你需要开始的while循环内

echo "<tr>";

和 以

结尾
echo "</tr>;

现在你只做一次

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签