Update the value of a field in database by 1 using codeigniter

有些话、适合烂在心里 提交于 2019-11-28 12:00:45
$this->db->set('usage', 'usage+1', FALSE);
$this->db->where('tag', 'java');
$this->db->update('tags');
Srihari Goud

You can also use something like this

$data = array('usage' => 'usage+1', *other columns*);
$this->db->where('tag', 'java');
$this->db->update('tags', $data);

UPDATE: $data was not being passed on to update

I find its sometimes simpler to just write the SQL rather than having Active Record build it for me.

$sql = 'update tags set usage=usage+1 where tag=?';
$this->db->query($sql, array($tag));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!