Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在CodeIgniter中一行内动态增加文章视图_Php_Codeigniter_Activerecord - Fatal编程技术网

Php 在CodeIgniter中一行内动态增加文章视图

Php 在CodeIgniter中一行内动态增加文章视图,php,codeigniter,activerecord,Php,Codeigniter,Activerecord,我的表中有一列名为counter,名为articles 问题是如何将本列中的值增加约1,因此在控制器或模型中,我将使用updatedb函数 我在想这样的事情: $id = 5; //article id (I will get that from the url or db, no problem with that) $this->db->update("current counter column value plus one where id column equals $

我的表中有一列名为counter,名为articles

问题是如何将本列中的值增加约1,因此在控制器或模型中,我将使用updatedb函数

我在想这样的事情:

 $id = 5; //article id (I will get that from the url or db, no problem with that)
 $this->db->update("current counter column value plus one where id column equals $id "); 
假设我得到了《观点》这篇文章:

$this->db->select_sum("counter")->get("articles");

我知道我需要验证用户的ip,例如,我不是在每次页面加载时都计算ip,而是在5分钟后才计算。但这是另一回事;)。我需要完成这个问题。

您可以使用常规查询(带绑定):

或者,使用AR:

$query = $this->db->update('articles')
                   ->set('counter','counter+1', FALSE)
                   ->where('id', $id);
set()中的第三个参数FALSE告诉它不要转义列名。
如果只需要增加视图数量,则不需要获取视图数量

$query = $this->db->update('articles')
                   ->set('counter','counter+1', FALSE)
                   ->where('id', $id);