【发布时间】:2023-03-25 21:25:01
【问题描述】:
我有一个简单的问题,如何回显月份数据?每个月通常有 2-3 头费用。例如,学费+学期费+活动费。
我想回显 4 月、7 月、8 月等所有存储值在 <table></table> 中。为此,我使用了两个 While 循环,第一个用于选择月份和类,第二个循环位于第一个循环内,用于在所选月份内打印值。但是循环多次打印相同的最高值。
例如,Apr 有 3 个头,在数据库表 Tution fee 上,现在循环打印 Tution fee 3 次。
请帮我解决这个问题。
代码如下:
<table class="table table-bordered responsive">
<tr>
<th colspan="2">
Fees Detail</th>
</tr>
<tr>
<th>Fee Name</th>
<th>Amount</th>
<th>Status</th>
</tr>
<?php
$data = mysqli_query($conn,"SELECT * FROM fees_on_class WHERE class = '$qry[class]' GROUP BY month_id ");
while($row = mysqli_fetch_array($data))
{
echo "<tr>";
echo "<th colspan='3'>"."<input type='checkbox' id='selectall'/>". "Month:- ".$row['month']."</th>";
echo "</tr>";
$d = mysqli_query($conn,"SELECT * FROM fees_on_class WHERE month = '$row[month]' AND class = '$row[class]' ");
while($r = mysqli_fetch_array($d))
{
echo "<tr>";
echo "<td>"."<input type='checkbox' class='case' name='case' value='1'/>".$row['fees_head']."</td>";
echo "<td>".$row['amount'];"</td>";
echo "<td>"."status"."</td>";
echo "</tr>";
}
}
?>
</table>
【问题讨论】: