我想从收入表中选择收入金额,更新总收入并从总收入中减去收入。然后删除该行。
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');
}
答案 0 :(得分:1)
除非我误解了您的问题,否则您需要执行以下操作:
从income_amount
表中选择income
:
$this->db->select('income_amount');
$query = $this->db->get('income');
$row = $query->row();
if (isset($row)) {
$income_amount = $row->income_amount;
}
通过从所有表格的total_income
值中删除$income_amount
来更新amount
表格:
$this->db->set('amount', 'amount-'.$income_amount);
$this->db->update('total_income');
从$id
表中删除income
标识的行:
$this->db->delete('income', array('income_id' => $id));