I want to get number of users who read blog .
what i have done -> when user open particular post then i update blog_read column with +1 of my last value, and it works
But i have an issue if user refresh that post it will again update blog_read column with +1 of my last value, I want to update when user open post from list of post, not update on every refresh.
My code:-
public function readBlog($url)
{
$q = $this->db->get_where('blog',array('blog_url'=>$url));
if($q->num_rows() > 0)
{
foreach ($q->result() as $item)
{
$val = $item->blog_read;
$val = $val+1;
$data = array('blog_read'=>$val);
$this->db->where('blog_url',$url);
$this->db->update('blog',$data);
}
}
}
public function getBlog($url)
{
$this->readBlog($url);
$q = $this->db->get_where('blog',array('blog_url'=>$url));
if($q->num_rows() > 0)
{
foreach ($q->result() as $item)
{
$data[] = $item;
}
return $data;
}
}