我需要显示表格中的结果,但是我的循环不会相应地生成表格,TH会针对每个结果循环,请协助
<?php foreach ($results as $results) : ?>
<table border="1">
<tr>
<th>Date</th>
<th>GBR</th>
<th>EUR</th>
<th>USD</th>
</tr>
<tr>
<td><?php echo $results['date'];?></td>
<td><?php echo $results['gbr']; ?></td>
<td><?php echo $results['eur']; ?></td>
<td><?php echo $results['usd']; ?></td>
</tr>
</table>
<?php endforeach; ?>
答案 0 :(得分:1)
你需要在循环中编写你的tr。
试试这个:
<table border="1">
<tr>
<th>Date</th>
<th>GBR</th>
<th>EUR</th>
<th>USD</th>
</tr>
<?php foreach ($results as $results) : ?>
<tr>
<td><?php echo $results['date'];?></td>
<td><?php echo $results['gbr']; ?></td>
<td><?php echo $results['eur']; ?></td>
<td><?php echo $results['usd']; ?></td>
</tr>
<?php endforeach; ?>
</table>
答案 1 :(得分:0)
只需使用动态显示数据的foreach
循环。
<table border="1">
<tr>
<th>Date</th>
<th>GBR</th>
<th>EUR</th>
<th>USD</th>
</tr>
<?php foreach ($results as $results) : ?>
<tr>
<td><?php echo $results['date'];?></td>
<td><?php echo $results['gbr']; ?></td>
<td><?php echo $results['eur']; ?></td>
<td><?php echo $results['usd']; ?></td>
</tr>
<?php endforeach; ?>
</table>
答案 2 :(得分:0)
每次都不要循环表。只需启动循环到<tr>
<?php foreach ($results as $results) : ?>
<tr>
<td><?php echo $results['date']; ?></td>
<td><?php echo $results['gbr']; ?></td>
<td><?php echo $results['eur']; ?></td>
<td><?php echo $results['usd']; ?></td>
</tr>
<?php endforeach; ?>
</table>
答案 3 :(得分:0)
无需在每个循环中包含table和th标记,只需将tr放入循环中即可。
<table border="1">
<tr>
<th>Date</th>
<th>GBR</th>
<th>EUR</th>
<th>USD</th>
</tr>
<?php foreach ($results as $result) : ?>
<tr>
<td><?= $result['date'];?></td>
<td><?= $result['gbr']; ?></td>
<td><?= $result['eur']; ?></td>
<td><?= $result['usd']; ?></td>
</tr>
<?php endforeach; ?>
</table>
试试这段代码希望是有帮助的