作爲一個新手,我的問題是,是這樣寫的PHP代碼是很好的做法,混合HTML和PHP還是有這樣做的更好的辦法結合PHP和HTML
<?php
if (isset($_POST['submit']))
{
$principal_balance = $_POST['principal_amount'];
$interest_rate = $_POST['interest_rate'];
$repayment_amount = $_POST['repayment_amount'];
echo "<html>";
echo "<head>";
echo "<title> Loans </title>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
echo" <link rel=\"stylesheet\" type=\"text/css\" href=\"styles/document.css\" />";
echo "<body>";
echo "<table>";
echo "<th> Principal Balance </th> <th> Interest Amount </th> <th> Principal Balance Amount Recovered </th> <th> Principal Balance </th> <th> Outstanding Balance </th>";
while ($principal_balance > 0)
{
if ($principal_balance < $repayment_amount)
{
exit;
}
else
{
$interest_amount = $interest_rate * $principal_balance * 1/12;
$principal_amount_recovered = $repayment_amount - $interest_amount;
$outstanding_balance = $principal_balance - $principal_amount_recovered;
round ($interest_amount, 2);
round ($principal_amount_recovered, 2);
round ($outstanding_balance, 2);
//echo $principal_balance . "," . $interest_amount . "," . $principal_amount_recovered . "," . $outstanding_balance . "<br />";
echo "<tr> <td>" . round ($principal_balance, 2) . "</td> <td>" . round ($interest_amount, 2) . "</td> <td>" . round ($principal_amount_recovered, 2). "</td> <td>" . round ($outstanding_balance, 2) . "</td> </td>";
$principal_balance = $outstanding_balance;
}
}
echo "</table>";
echo "</body>";
echo "</html>";
}
?>
對於像這樣的獨立腳本,沒有真正的問題。當您開始製作更大更復雜的腳本時,您需要考慮某種組織,例如[MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%% 93控制器) – Ross 2011-05-26 11:49:14