CodeIgniter / PHP Active Record不会递增一个整数 [英] CodeIgniter/PHP Active Record won't increment an integer

查看:137
本文介绍了CodeIgniter / PHP Active Record不会递增一个整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的查询,在CodeIgniter的活动记录:

  function calculate_invites($ userid)
{
$ this-> db-> where('id',$ userid)
- > update('users',array('invites'=>'invites-1','sentinvites' >'sentinvites + 1'),FALSE);
}

字段邀请 sentinvites 都是整数,但在函数运行后设置为0。这使我想到CodeIgniter传递 invites-1 sentinvites + 1 作为字符串,但我认为添加<$



谢谢!

p> Jack

解决方案

这不适用于 update



这应该可以工作:

  $ this-> db-> where('id',$ userid); 
$ this-> db-> set('invites','invites-1',FALSE);
$ this-> db-> set('sentinvites','sentinvites + 1',FALSE);
$ this-> db-> update('users');

这也可以使用用户指南有点不清楚):

  $ this-> db-> where('id',$ userid); 
$ this-> db-> set(array('invites'=>'invites-1','sentinvites'=>'sentinvites + 1'),FALSE);
$ this-> db-> update('users');


Here's my query, in CodeIgniter's Active Record:

function calculate_invites($userid)
{
    $this->db->where('id', $userid)
               ->update('users', array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE);
}

The fields invites and sentinvites are both integers but are set to 0 after the function is run. This makes me presume that CodeIgniter is passing invites-1 and sentinvites+1 as strings, but I thought appending FALSE to the end stopped it doing that?

Thanks!

Jack

解决方案

This doesn't work with update, only with set.

This should work:

$this->db->where('id', $userid);
$this->db->set('invites', 'invites-1', FALSE);
$this->db->set('sentinvites', 'sentinvites+1', FALSE);
$this->db->update('users');

This may work too (the user guide is a bit unclear):

$this->db->where('id', $userid);
$this->db->set(array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE);
$this->db->update('users');

这篇关于CodeIgniter / PHP Active Record不会递增一个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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