SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: view count

  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    view count

    Im looking to make a page with how many times a page has been accessed/viewed.

    I have a sub-table timesviewed in one of my database tables.

    I had this code from something else where it would count the comments given to a certain image, but I havent figured out how to make it become a counter.

    PHP Code:
     
     
    $id 
    $_GET['id'];

    $query="
    SELECT COUNT( commenttext ) AS count
    FROM comments
    WHERE comments.photoid = '
    $id'";

     
    $res mysql_query($query); //I'm assuming the above query is in $query
    $row mysql_fetch_assoc($res);
    $count $row['count']; //And this is why I added "AS count" to the query 

    This just tells me how many comments there are according to the image, but not how to get a counter going for the amount of views per page.

    How would I go about doing that?




    EDIT:: Scratch that- I looked back at what I was doing and figured it out::
    PHP Code:
     $times $timesviewed 1;
        
     
    $sql mysql_query("UPDATE work SET
              timesviewed = '
    $times
              WHERE photoid = '
    $pid'"); 

  2. #2
    SitePoint Enthusiast mrsmiley's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And here I was all set to be helpful

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,446
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    increment

    Where are you getting the value for $timesviewed ??
    If you are doing a SELECT to get it and then doing the UPDATE you should be able to simplify things by letting the database increment the value in a single query.
    PHP Code:
    $sql mysql_query("UPDATE work SET
              timesviewed = timesviewed + 1
              WHERE photoid = '
    $pid'"); 

  4. #4
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the timesviewed was already retrieved for another query a few lines before.


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
  •