1
用於填充表的循環。但我不斷收到額外的兩列,重複前兩列的數據。我的for循環出了什麼問題?所有的幫助表示讚賞。用PHP for循環填充html表
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Calculating Interest</title>
<style>
table {
border: 3px solid black;
border-color: black;
text-align: left;
padding: 1px;
}
th {
background-color: #01008A;
color: white;
}
tr:nth-child(odd) {background-color: #AED8E6}
</style>
</head>
<body>
<table>
<tr>
<th>Year</th>
<th>Amount on deposit</th>
</tr>
<?php
for($i = 1; $i <= 10; $i++) {
echo "<tr>";
for ($j = 1; $j <= 2; $j++) {
$p = 1000;
$r = 0.05;
$n = 1;
echo "<td>" . $i . "</td>";
echo "<td>" . ($p = number_format(($p * pow((1 + $r), $i)), 2)) . "</td>";
$n++;
}
echo "</tr>";
}
?>
</table>
</body>
</html>
由於嵌套for循環 – JYoThI
除去此循環'爲($ J = 1; $Ĵ<= 2; $ J ++' – Nidhi
變更線32,爲($ J = 1; $Ĵ <2; $ j ++){ – sudo