SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    view counter code

    Hello,

    Am I on the right track to create code for view counter in php?
    I am using codeIgniter framework.
    My code is:
    Code PHP:
      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;
            }

    or is there any other way?

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Why not just...
    PHP Code:
    <?php
    function update_view_count($topic_id)
    {
        return (
    $this->db->query("UPDATE forum_topics SET viewcount = viewcount + 1 WHERE id = $topic_id")) ? true false ;
    }
    ?>
    ?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •