我有两个值,数据库中也有两列,我希望每次函数运行时,它都会用相应的值来增加数据库列的值,
public function converted(){ $id = $this->session->userdata('user_id'); $newresult = 1; $newpoints = 1000; $data = array( 'total' => `total`+$newresult, 'point' => `point`-$newpoints ); $this->db->where('money.uis',$id); $this->db->update('money',$data); }
我无法更新到数据库。运行完这个代码后我只得到 total 1 和 point = -1000
total
1
point
-1000
Codeigniter专门为不逃逸的文字
$this->db->set($key, $value = '', $escape = NULL)
$this->db->set('points', 'points + ' .$newpoints, FALSE); $this->db->set('total', 'total + ' . $newresult, FALSE); $this->db->where('money.uis',1); $this->db->update('money');