我在使用++增量打印表时遇到了一些麻烦。它目前打印出每行的标题,如下所示:
Year Amount owed
1 $234,500
Year Amount owed
2 $218,473
Year Amount owed
3 $201,901
...
这是代码:
while ($current_owed > 0) {
$current_owed = (($current_owed*$annual_interest)+$current_owed)-$yearly_payment;
print "<table border=\"1\">
<tr>
<th>Year</th>
<th>Amount owed</th>
</tr>
<tr><td>" . $year . "</td><td>$currency" . number_format($current_owed, 0) . "</td>
</tr>
</table>";
$year++;
}
答案 0 :(得分:1)
是的,因为您打印<th>Year</th> <th>Amount owed</th
&gt;在while循环中,这意味着您打印每行的表头。把
<th>Year</th>
<th>Amount owed</th>
在循环之前应该没问题
答案 1 :(得分:1)
帮自己一个忙,并格式化您的代码,以便更容易阅读和理解。使调试这样的小问题变得更加容易。
<table border="1">
<tr>
<th>Year</th>
<th>Amount owed</th>
</tr>
<?php
while ($current_owed > 0) {
$current_owed = (($current_owed*$annual_interest)+$current_owed)-$yearly_payment;
?>
<tr>
<td><?php echo $year ?></td>
<td><?php echo $currency.number_format($current_owed, 0) ?></td>
</tr>
<?php
$year++;
}
?>
</table>