[英]Display data using while loop from SQL database php dpo into html table not working
[英]Display php data in a html table using while loop
每次我使用while循环从数据库中回显信息时,第一个结果仅显示在一行中,而其余结果作为原始文本打印在表外。
<table class="table table-striped">
<thead>
<tr class="bg-info">
<th>Id</th>
<th>Customer</th>
<th>Order</th>
<th>Title</th>
<th>Quantity</th>
<th>Total</th>
<th>Paid</th>
<th>Created Time</th>
<th>Updated Time</th>
<th>Update Order</th>
<th>Delete Order</th>
</tr>
</thead>
<tbody>
<?php
if($sql->num_rows > 0){
while($data = $sql->fetch_array()):
?>
<tr>
<td><?php echo $database->escape_value($data['custom_id']); ?></td>
<td><?php echo $database->escape_value($data['order_id']); ?></td>
<td><?php echo $database->escape_value($data['title']); ?></td>
<td><?php echo $database->escape_value($data['quantity']); ?></td>
<td><?php echo $database->escape_value($data['total']); ?></td>
<td><?php echo $database->escape_value($data['paid']); ?></td>
<td><?php echo $database->escape_value($data['created_at']); ?></td>
<td><?php echo $database->escape_value($data['updated_at']); ?></td>
<td><a href="update_order.php?id=<?php echo $database->escape_value($data['id']); ?>">Update Order</a></td>
<td><a href="delete_order.php?id=<?php echo $database->escape_value($data['id']); ?>" onClick="return confirm('Are you sure you want to delete this order?'); ">Delete</a></td>
</tr>
</tbody>
</table>
<?php endwhile; }else
echo "<div class='btn bg-danger'>search not found</div>";
?>
伙计们,只有第一个结果会正确地显示在表格中,我希望所有数据都显示在表格中。
您正在关闭循环内的表。 重要的是,只保留一段时间。
然后小心地正确合上所有支架。
<thead>
<tr class="bg-info">
<th>Id</th>
<th>Customer</th>
<th>Order</th>
<th>Title</th>
<th>Quantity</th>
<th>Total</th>
<th>Paid</th>
<th>Created Time</th>
<th>Updated Time</th>
<th>Update Order</th>
<th>Delete Order</th>
</tr>
</thead>
<tbody>
<?php
if($sql->num_rows > 0){
while($data = $sql->fetch_array()){
?>
<tr>
<td><?php echo $database->escape_value($data['custom_id']); ?></td>
<td><?php echo $database->escape_value($data['order_id']); ?></td>
<td><?php echo $database->escape_value($data['title']); ?></td>
<td><?php echo $database->escape_value($data['quantity']); ?></td>
<td><?php echo $database->escape_value($data['total']); ?></td>
<td><?php echo $database->escape_value($data['paid']); ?></td>
<td><?php echo $database->escape_value($data['created_at']); ?></td>
<td><?php echo $database->escape_value($data['updated_at']); ?></td>
<td><a href="update_order.php?id=<?php echo $database->escape_value($data['id']); ?>">Update Order</a></td>
<td><a href="delete_order.php?id=<?php echo $database->escape_value($data['id']); ?>" onClick="return confirm('Are you sure you want to delete this order?'); ">Delete</a></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
if($sql->num_rows == 0){
echo "<div class='btn bg-danger'>search not found</div>";
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.