作为一个新手,我的问题是,是这样写的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