Create a Cumulative Sum Column in codeigniter |
I have this table pc_expenditure
Code: MariaDB [paper2]> select * from pc_expenditure; +----------------------+-------------------------+-------------------+---------------+---------------------+ | pc_expenditureID | expensetypesID | receipt_no | details | amount_spent | +----------------------+-------------------------+-------------------+---------------+---------------------+ | 1 | 1 | 345 | transport | 43 | | 2 | 2 | 3456 | water | 50 | +----------------------+-------------------------+-------------------+---------------+---------------------+ I'd like to get a cumulative sum(running total) for each column in codeigniter but it's kind tricky it returns all the values in the same column I don't know how to go around it. cumulative sum Code: MariaDB [paper2]> select expensetypesID, amount_spent, (@csum := @csum + amount_spent) as cumulative_sum +--------------------+------------------+---------------------+ | expensetypesID | amount_spent | cumulative_sum | +--------------------+------------------+---------------------+ | 1 | 43 | 43 | | 2 | 50 | 93 | +--------------------+------------------+---------------------+ Below is my code in codeigniter model PHP Code: function get_pettycash_amount() { controller PHP Code: $this->data['original'] = $this->pc_expenditure_m->get_pettycash_amount($schoolyearID); view PHP Code: <td data-title="<?=$this->lang->line('pettycash_bal')?>"> the above code display this kind of result; +--------------------+------------------+---------------------+ | expensetypesID | amount_spent | balance | +--------------------+------------------+---------------------+ | 1 | 43 | 43,93| | 2 | 50 | 43,93| +--------------------+------------------+---------------------+ which is slightly different from the second table. |
Messages In This Thread |
Create a Cumulative Sum Column in codeigniter - by kayinja.denis - 01-08-2018, 12:52 PM
RE: Create a Cumulative Sum Column in codeigniter - by jreklund - 01-08-2018, 01:45 PM
RE: Create a Cumulative Sum Column in codeigniter - by kayinja.denis - 01-08-2018, 02:17 PM
RE: Create a Cumulative Sum Column in codeigniter - by jreklund - 01-08-2018, 02:47 PM
RE: Create a Cumulative Sum Column in codeigniter - by kayinja.denis - 01-10-2018, 02:44 AM
|