Codeigniter,通过变量中包含的值增加数据库值 [英] Codeigniter, increase database value by value contained in variable

查看:89
本文介绍了Codeigniter,通过变量中包含的值增加数据库值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用codeigniter,并且在我的模型中具有以下功能可以为用户提供积分.但是,它不起作用,而是将points列设置为0.

I am using codeigniter, and I have the following function in my model to give points to the user. It is however not working, rather setting the points column to 0.

这是在codeigniter手册中编写的方式.因此,我不知道为什么它不起作用...

This is how it is written in the codeigniter manual. Therefore I have no clue why it is not working...

谢谢

function give_points($username,$points)
{
    $this->db->set('points', 'points + $points');
    $this->db->where('username', $username);
    $this->db->update('users'); 
    echo"done";
}

推荐答案

我相信您必须专门告诉CI 转义文本.我没有方便的CI安装程序来进行测试,但我认为它类似于:

I believe you have to tell CI specifically to not escape the text. I don't have a CI installation handy to test this in, but I think it was something like:

$this->db->set('points', 'points + ' . (int) $points, FALSE);

这篇关于Codeigniter,通过变量中包含的值增加数据库值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆