【问题标题】:CodeIgniter Active Record +1CodeIgniter 活动记录 +1
【发布时间】:2014-10-19 17:37:35
【问题描述】:

我怎么做那个查询:

UPDATE `xxx` SET `xx`=xx+1

在 Codeigniter 中使用 Active Record 吗?

感谢您的帮助 ;-)

【问题讨论】:

标签: php codeigniter active-record-query


【解决方案1】:

试试这个

$this->db->where('id',$id);
$this->db->update('xxx',array('xx',$xx+1));

【讨论】:

    【解决方案2】:
    $this->db->where('id', 'yourid');
    $this->db->set('xx', '`xx`+1', FALSE);
    $this->db->update('xxx');
    

    注意set函数中的第三个参数。

    此函数告诉 CodeIgniter 不要在字段上添加反引号 (`)。

    【讨论】:

    • 嗨@LeonardoVendoChanzi,如果我的回答对你有用,请接受它作为解决方案。
    • 是的,你必须等待 7 分钟... :)
    【解决方案3】:

    试试下面的代码:

    //$this->db->where('id', 'yourid');
    $this->db->set('xx', 'xx+1',FALSE);
    $this->db->update('xxx');
    

    【讨论】:

      猜你喜欢
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-10
      • 2014-04-05
      • 2012-06-14
      • 2012-04-09
      • 2014-06-25
      相关资源
      最近更新 更多