Php 如何计算codeigniter博客中的帖子浏览量

Php 如何计算codeigniter博客中的帖子浏览量,php,codeigniter,Php,Codeigniter,我是codeigniter和php的新手 我想计算后视图的数量并将其存储到数据库中 这意味着,我想通过计算帖子浏览量来创建一个流行的帖子插件 但我不能这么做 请任何人帮帮我。指路 这是我的文章 对不起,我英语不好。明星情结怎么办 $post_id = "???" if(isset($_COOKIE['read_articles'])) { //grab the JSON encoded data from the cookie and decode into PHP Array $re

我是codeigniter和php的新手

我想计算后视图的数量并将其存储到数据库中

这意味着,我想通过计算帖子浏览量来创建一个流行的帖子插件

但我不能这么做

请任何人帮帮我。指路

这是我的文章

对不起,我英语不好。

明星情结怎么办

$post_id = "???"
if(isset($_COOKIE['read_articles'])) {
  //grab the JSON encoded data from the cookie and decode into PHP Array
  $read_articles = json_decode($_COOKIE['read_articles'], true);
   if(isset($read_articles[$post_id]) AND $read_articles[$post_id] == 1) {
     //this post has already been read
   } else {

     //increment the post view count by 1 using update queries

     $read_articles[$post_id] = 1;
     //set the cookie again with the new article ID set to 1
     setcookie("read_articles",json_encode($read_articles),time()+60*60*24);  

   }

} else {

  //hasn't read an article in 24 hours?
  //increment the post view count
  $read_articles = Array(); 
  $read_articles[$post_id] = 1;
  setcookie("read_articles",json_encode($read_articles),time()+60*60*24);      

}
//函数单post,查询通过slug和id post获取
if(!isset($_SESSION['views'.$id])| |(isset($_SESSION['views'.$id])&&$_SESSION['views'.$id]!=$id)){
$this->post_m->viewer($id);//加载模型查看器
$this->session->set_userdata('视图'.$id,$id);
}
//模型“post\m”
函数查看器($id)
{
$this->db->where('id',$id);
$this->db->set('views','views+1',FALSE);
$this->db->update('posts');//表更新
} 

$id是id post
请更清楚地说明您的查询。还可以添加一些您尝试过的代码。
     public function get($id = NULL, $single = FALSE){

    if ($id != NULL) {
        $filter = $this->_primary_filter;
        $id = $filter($id);
        $this->db->where($this->_primary_key, $id);
        $method = 'row';
    }
    elseif($single == TRUE) {
        $method = 'row';
    }
    else {
        $method = 'result';
    }

    if (!count($this->db->ar_orderby)) {
        $this->db->order_by($this->_order_by);
    }
    return $this->db->get($this->_table_name)->$method();
}
$post_id = "???"
if(isset($_COOKIE['read_articles'])) {
  //grab the JSON encoded data from the cookie and decode into PHP Array
  $read_articles = json_decode($_COOKIE['read_articles'], true);
   if(isset($read_articles[$post_id]) AND $read_articles[$post_id] == 1) {
     //this post has already been read
   } else {

     //increment the post view count by 1 using update queries

     $read_articles[$post_id] = 1;
     //set the cookie again with the new article ID set to 1
     setcookie("read_articles",json_encode($read_articles),time()+60*60*24);  

   }

} else {

  //hasn't read an article in 24 hours?
  //increment the post view count
  $read_articles = Array(); 
  $read_articles[$post_id] = 1;
  setcookie("read_articles",json_encode($read_articles),time()+60*60*24);      

}