php mysql中的用户帐户报告,如银行存折

时间:2015-09-22 07:38:02

标签: php mysql codeigniter

我们创建了一个客户会计报告,如银行通行证 -

| Date |  Debit | Credit | End Balance |

6/7/15    678 Rs    300 Rs       378 Rs    // (End Balance = Debit-Credit)

7/8/15    345 Rs    123 Rs       600 Rs    //(End Balance = (378+345)-123=600) 

4/9/15    123 Rs    70 Rs        653 Rs    //(End Balance = (600+123)-70=653)

.............................................. < / p>

我们可以从表中轻松打印日期,信用,借记值 -

     <table>

    <thead>
    <tr>
     <th>date</th>
    <th>debit</th>
    <th>credit</th>
    <th>End Balance</th>
    </tr>
   </thead>


    <tbody>
  foreach ($rows as $row):
     <tr>
<td> $rows->date </td>
<td> $rows->debit</td>
<td> $rows->credit</td>
<td>...........</td>
    </tr>
  endforeach;
    </tbody>

        </table>

我们不明白我们使用什么机制,我目前的最终余额总是加上最后的余额,然后减去当前的贷方余额?

1 个答案:

答案 0 :(得分:4)

StackOverflow不是一个免费的代码开发服务,但因为我心情愉快,感觉很慷慨:

<table>
    <thead>
        <th>date</th>
        <th>debit</th>
        <th>credit</th>
        <th>End Balance</th>
    </thead>
    <tbody><?php 
        $prevBalance = 0;
        foreach($rows as $row): 
            $balance = ($prevBalance + $row->credit) - $row->debit; ?>
            <tr>
               <td><?php echo($row->date); ?></td>
               <td><?php echo($row->debit); ?></td>
               <td><?php echo($row->credit); ?></td>
               <td><?php echo($balance); ?></td>
            </tr><?php
        $prevBalance = $balance;
        endforeach; ?>
    </tbody>
</table>