无法在codeigniter中增加或减少数据库列的值

时间:2018-11-05 13:00:36

标签: php mysql codeigniter

我有两个值,并且我在数据库中也有两个列,我希望每次函数运行时都将使用各自的值来递增数据库列的值,

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 = 1point = -1000;

1 个答案:

答案 0 :(得分:1)

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');