[英]Hi what i am doing wrong with this query?
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');
}
Unless I have misunderstood your question, you want to do the following :除非我误解了您的问题,否则您要执行以下操作:
Select income_amount
from the income
table :从
income
表中选择income_amount
:
$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 :通过从表的所有
amount
值中减去$income_amount
来更新total_income
表:
$this->db->set('amount', 'amount-'.$income_amount); $this->db->update('total_income');
Delete the row identified by $id
from the income
table :从
income
表中删除$id
标识的行:
$this->db->delete('income', array('income_id' => $id));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.