view counter code
Posted: Fri May 08, 2009 4:59 am
Hello,
Am I on the right track to create code for view counter in php?
I am using codeIgniter framework.
My code is:
or is there any other way?
Am I on the right track to create code for view counter in php?
I am using codeIgniter framework.
My code is:
Code: Select all
function update_view_count($topic_id)
{
$count = 0;
$query = "SELECT viewcount FROM forum_topics WHERE id = '".$topic_id."'";
$temp=$this->db->query($query);
foreach($temp->result() as $value)
{
$count = $value->viewcount;
}
$count = $count + 1;
$query="UPDATE forum_topics SET viewcount = $count WHERE id=$topic_id";
$temp = $this->db->query($query);
return $count;
}