How can I achieve a sum of each individual column ie. Due Principal, Interest, and Total Monthly Payment using a for loop. I want the result to be output in the (-----------) section below the table. Any help?
<pre><h1>Loan Repayment Schedule</h1> <p>Amount Taken: 1,000,000</p> <p>Period: 12 Months</p> <p>Interest: 2%</p> <table border="1"> <thead> <tr> <th>Month</th> <th>Due Date</th> <th>Description</th> <th>Due Principal</th> <th>Interest</th> <th>Total Monthly Payment</th> <th>Principal Balance</th> </tr> </thead> <tbody> <?php $balance = 1000000; $period = 12; $emi = $balance/$period; $payment_date = date('2022-09-28'); for ($i=1; $i <=$period; $i++){ $interest = ((2/100)*$balance); $principal = $emi +$interest; $balance = $balance - $emi; $payment_date = date("jS F, Y",strtotime("+1 month",strtotime($payment_date))); ?> <tr> <td><?php echo $i;?></td> <td><?php echo $payment_date;?></td> <td>Repayment</td> <td><?php echo number_format($emi);?></td> <td><?php echo number_format($interest);?></td> <td><?php echo number_format($principal);?></td> <td><?php echo number_format($balance);?></td> </tr> <?php } ?> </tbody> <tfoot> <tr> <th></th> <th></th> <th></th> <th>-----------</th> <th>-----------</th> <th>-----------</th> <th></th> </tr> </tfoot> </table>
<pre lang="HTML"><pre><h1>Loan Repayment Schedule</h1> <p>Amount Taken: 1,000,000</p> <p>Period: 12 Months</p> <p>Interest: 2%</p> <table border="1"> <thead> <tr> <th>Month</th> <th>Due Date</th> <th>Description</th> <th>Due Principal</th> <th>Interest</th> <th>Total Monthly Payment</th> <th>Principal Balance</th> </tr> </thead> <tbody> <?php $balance = 1000000; $period = 12; $emi = $balance/$period; $payment_date = date('2022-09-28'); for ($i=1; $i <=$period; $i++){ $interest = ((2/100)*$balance); $principal = $emi +$interest; $balance = $balance - $emi; $payment_date = date("jS F, Y",strtotime("+1 month",strtotime($payment_date))); ?> <tr> <td><?php echo $i;?></td> <td><?php echo $payment_date;?></td> <td>Repayment</td> <td><?php echo number_format($emi);?></td> <td><?php echo number_format($interest);?></td> <td><?php echo number_format($principal);?></td> <td><?php echo number_format($balance);?></td> </tr> <?php } ?> </tbody> <tfoot> <tr> <th></th> <th></th> <th></th> <th>-----------</th> <th>-----------</th> <th>-----------</th> <th></th> </tr> </tfoot> </table>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)