Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    count image views and update db

    hi,

    so i've uploaded an image to a dir and stored SOME info on db eg, album, user, file name and extension.

    Now my last job, to count views.....

    i have image.php (came up with):
    PHP Code:
    <?php 
    /********************************

        IMG-ize Script 2012
        @version: 3.0
        
        @auth0or: Chris Reynolds
        
        Copyright 2012 Chris Reynolds
        
    ********************************/

    include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/init.php' /*die('Can\'t find file.')*/;

    $id $_REQUEST['id'];

    $img mysql_query("SELECT * FROM images WHERE id = '$id'");
    $img mysql_fetch_assoc($img);

    $img $img['image'];

    header("Content-type: image/jpeg");

    echo 
    $img;
    ?>
    I'm thinking that's good for the job ^^^^^^^^^^

    hmm now one needs help updating view count and for that echo ^^^^^^ should i add the dir?

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    Just create another column in the image table and increment it each time you run your query

    something like

    PHP Code:
    $img mysql_query("SELECT * FROM images WHERE id = '$id'"); 
    $img mysql_fetch_assoc($img); 
    $inc $img['count'] +1;
    $cnt mysql_query("UPDATE images SET `count` = ".$inc." WHERE id = '$id'"); 

  • Users who have thanked Arcticwarrio for this post:

    Chris-2k (07-19-2012)

  • #3
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Thanks that worked!


  •  

    Posting Permissions

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