Reputation: 11
I want to select the income amount from income table, update the total income and subtract the income from the total income. Then delete the row.
public function delete($id)
{
$this->db->get('income');
$this->db->select('income_amount');
$this->db->query('update total_income set amount=amount-'.$this->db->select('income_amount'));
$this->db->where('income_id', $id);
$this->db->delete('income');
}
Upvotes: 1
Views: 47
Reputation: 149
Unless I have misunderstood your question, you want to do the following :
Select income_amount
from the income
table :
$this->db->select('income_amount');
$query = $this->db->get('income');
$row = $query->row();
if (isset($row)) {
$income_amount = $row->income_amount;
}
Update the total_income
table by substracting $income_amount
from all the amount
values of the table :
$this->db->set('amount', 'amount-'.$income_amount);
$this->db->update('total_income');
Delete the row identified by $id
from the income
table :
$this->db->delete('income', array('income_id' => $id));
Upvotes: 1