Update multiple table from CSV in Cpdeigniter |
[eluser]Ignis Avis[/eluser]
I am parsing a CSV file to add recrods to a table. this is how I do it. Code: foreach($csvData as $key => $row) { I have another table named monthly_due where there is three columns Code: 1)md_work_id When uploading a csv file to store data to table monthly fee i also want to update the monthly_due table where mf_work_id from csv matches md_work_id. Code: md_due = md_due - 'mf_amount' How should I do it?
[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) then call that function from within your existing code: Code: foreach($csvData as $key => $row) { That should do it? Of course you could move the new function to a model and then call it from your existing code: Code: ... I may have got some syntax wrong but that's roughly how I would do it, I think!
[eluser]Ignis Avis[/eluser]
@flemming I have implemented what you suggested. But now I am getting an DB error Code: Error Number: 1054 Why is this happening?
[eluser]Tim Brownlaw[/eluser]
Code: function update_monthly_due($md_work_id, $mf_amount) Your md_work_id is obviously a string and not an integer... So it needs to be wrapped in quotes ''... So you would then have... Code: function update_monthly_due($md_work_id, $mf_amount) The {} is a little trick for helping to separate variables in a Double Quoted String. You could try it on the others... but see if that works first. |
Welcome Guest, Not a member yet? Register Sign In |