【发布时间】: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>
【问题讨论】:
-
标签(即行标签)也应该在循环中。 并在循环外取出<tr>和</tr>。感谢所有修复它的人。很抱歉延迟了一段时间远离编码。感谢您的所有帮助!
标签: php mysqli html-table