代码之家  ›  专栏  ›  技术社区  ›  Codecraker

无法在codeigniter中递增或递减数据库列值

  •  0
  • Codecraker  · 技术社区  · 7 年前

    我有两个值,数据库中也有两列,我希望每次函数运行时,它都会用相应的值来增加数据库列的值,

    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

    1 回复  |  直到 7 年前
        1
  •  2
  •   Rajeev Ranjan    7 年前

    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');
    
    推荐文章