![](/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.