codeigniter mysql不时更新惩罚

I have this at my model, I want to update the price everynow and then, I want that everytime I open the controller it will add up 100 to the Penalty, how do I do that? what is wrong with my query? Probably because of the update right? I dont know plz help! If I put 200 at 'Penalty' + 200 it will go for 200 and then if I put 100 it puts 100 again

public function addPenalty(){
    $data = array(
        'Penalty' => 'Penalty' + 100
        );
    $this->db->where('Active',1);
    $query = $this->db->update('tbl_client_penalties',$data);
    return $query;
}
duanchifo2866
duanchifo2866 我只是在查询中看到我认为它是正确的!它有什么问题吗?
大约 4 年之前 回复
doutu7123
doutu7123 什么是Penalty的罚款'+100?
大约 4 年之前 回复
doucongqian6644
doucongqian6644 检索Penalty的值,然后向其中添加100,然后使用更新的值更新表。
大约 4 年之前 回复

2个回答

Try this code

$this->db->set('Penalty', 'Penalty + '.100, FALSE);
$this->db->where('Active',1);
$this->db->update('tbl_client_penalties');

for more information check the document.

Try this code

$dbdata["Penalty"] = "Penalty + 100";
$this->db->update("tbl_client_penalties", $dbdata, array('Active' => 1));
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐