用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2823|回复: 2
收起左侧

[HELP] 数据库某字段累加

[复制链接]
发表于 2012-11-21 00:11:04 | 显示全部楼层 |阅读模式
PHP复制代码
$datas['ip'] = $ip;            $datas['city'] = $city;
            $datas['num'] = "num + 1";
            $this->db->update('fw_codelibrary', $datas, array('code' => $code));
复制代码

打印出来的语句是这样的。
SQL复制代码
UPDATE `fw_codelibrary` SET `latstime` = 1353427227, `ip` = '127.0.0.1', `city` = '', `num` = 'num + 1' WHERE `code` = '1000810'
复制代码


`num` = 'num + 1' 多了一个单引号,不计算,,如何把这个单引号去掉了
发表于 2012-11-21 00:36:20 | 显示全部楼层
PHP复制代码
 
$this->db->set('ip', $ip)
->set('city', $city)
->set('num', 'num+1', FALSE)
->where('code', $code)
->update('fw_codelibrary');
 
复制代码


http://codeigniter.com/user_guid ... _record.html#insert
 楼主| 发表于 2012-11-21 16:25:10 | 显示全部楼层
谢谢

本版积分规则