首页 > 解决方案 > 如何在表格中自动显示计数数据累积和残差数据?

问题描述

我有一个问题,我在显示累积和剩余时使用直线法。我想知道如何使用 php 来自动计算。

这是用于提交数据的表格:

    <h1>Penyusutan</h1>
    <table>
      <form action="deprecalc.php" method="post">
        <label>Nominal : </label>
        <input type="text" name="nominal"><br>
        <label>Lama Depresiasi : </label>
        <input type="text" name="depresiasi"><br>
        <label>Awal : </label>   
        <input type="text" name="awal"><br>
        <label>Akhir : </label>   
        <input type="text" name="akhir"><br>
        <label>Residu Aset : </label>   
        <input type="text" name="residu"><br>
        <input type="submit">
      </form>
    </table>

这是php处理:

<?php
    $nominal = $_POST['nominal'];
    $depresiasi = $_POST['depresiasi'];
    $awal = $_POST['awal'];
    $akhir = $_POST['akhir'];
    $residu = $_POST['residu'];
?>

<h2>Nominal : <?php echo $nominal;?></h2></br>
<h2>Despresiasi : <?php echo $depresiasi;?></h2></br>
<table id="values">
    <tr>
        <th>Nominal</th>
        <th>Tahun</th>
        <th>Umur</th>
        <th>Akumulasi</th>
        <th>Residu</th>
    </tr>
<?php 
    $no  = 1;
    $years = date('Y');
    for ($i=0; $i < $depresiasi ; $i++) { 
        $rumus = ($nominal - $residu) / $depresiasi;
        $rumusResidu = ($nominal - $rumus);
?>

    <tr>
        <?php  echo "<td>".$nominal."</td>"   ?>
        <?php  echo "<td>".$years++."</td>"   ?>
        <?php  echo "<td>".$no++."</td>"   ?>
        <?php  echo "<td>".$rumus."</td>"   ?>

    <?php  echo "<td>".$rumusResidu."</td>"   ?>
</tr>
<?php   } ?>
</table>

我所做的结果是:

我所做的结果 附上预期的结果:我该如何实现?谢谢

但我想要这样的结果

标签: php

解决方案


推荐阅读