![](/img/trans.png)
[英]How to get data from many to many relationship table and print all rows in one line PHP
[英]How to Print all the rows in a table instead of one using PHP?
我有一个五行的表,我写了一个 php 代码来打印表中的所有行。 但不幸的是,我错过了一些代码,它实际上触发了获取数据的连续性,而不是从表中获取一行。
我的代码如下:
<?php
$sql2 = "SELECT * FROM useraddmoneyhistory ORDER BY date DESC";
$result2 = $conn->query($sql2);
if ($result2->num_rows > 0) {
$index = 0;
while($row2 = $result2->fetch_assoc()) {
$index++;
?>
<table class="table table-hover" >
<tr>
<th>ID</th>
<th>Mobile</th>
<th>Earlier Balance</th>
<th>Amount</th>
<th>Discount</th>
<th>Date</th>
</tr>
<tr >
<td><?php echo ($row2["id"]); ?></td>
<td><?php echo ($row2["mobile"]); ?></td>
<td><?php echo ($row2["preamount"]); ?></td>
<td><?php echo ($row2["amount"]); ?></td>
<td><?php echo ($row2["amountdis"]); ?></td>
<td><?php echo ($row2["date"]); ?></td>
</tr>
</table>
任何帮助是极大的赞赏...
您必须将 html 放入循环中,在代码中while
和if
语句未关闭。
<table class="table table-hover" >
<tr>
<th>ID</th>
<th>Mobile</th>
<th>Earlier Balance</th>
<th>Amount</th>
<th>Discount</th>
<th>Date</th>
</tr>
<?php
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
?>
... HTML 'tr' CODE ...
<?php
} // close while
$result->free();
} //close if
print "</tr></table>";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.