Welcome Guest, Not a member yet? Register   Sign In
Update multiple table from CSV in Cpdeigniter
#2

[eluser]Flemming[/eluser]
You could create a new function, e.g. update_monthly_due() and pass in parameters: md_work_id, mf_amount

Then your new function will do a mysql update like this:

UPDATE monthly_due set md_due = md_due - $mf_amount, md_paid = md_paid - $mf_amount WHERE md_work_id = $md_work_id

Code:
function update_monthly_due($md_work_id, $mf_amount)
{
$sql = "UPDATE monthly_due set md_due = md_due - " . $mf_amount . ", md_paid = md_paid - " . $mf_amount . " WHERE md_work_id = " . $md_work_id;
$this->db->query($sql);
}

then call that function from within your existing code:

Code:
foreach($csvData as $key => $row) {
            $data_n[$key] = array(
                'mf_date' => $row['mf_date'],
                'mf_work_id' => $row['mf_work_id'],
                'mf_sender' => $row['mf_sender'],
                'mf_amount' => $row['mf_amount'],
                'mf_trx_id' => $row['mf_trx_id'],
                );
            $this->db->insert('monthly_fee', $data_n[$key]);
            $this->update_monthly_due($row['mf_work_id'], $row['mf_amount']);
        }

That should do it?

Of course you could move the new function to a model and then call it from your existing code:

Code:
...
$this->some_model->update_monthly_due($row['mf_work_id'], $row['mf_amount']);

I may have got some syntax wrong but that's roughly how I would do it, I think!


Messages In This Thread
Update multiple table from CSV in Cpdeigniter - by El Forum - 08-21-2014, 02:01 AM
Update multiple table from CSV in Cpdeigniter - by El Forum - 08-21-2014, 06:51 AM
Update multiple table from CSV in Cpdeigniter - by El Forum - 08-22-2014, 11:04 PM
Update multiple table from CSV in Cpdeigniter - by El Forum - 08-23-2014, 01:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB