Results 1 to 3 of 3

Thread: Addimg Images to a database + Hit counter

Threaded View

  1. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Addimg Images to a database + Hit counter

    You need to be viewing the image on a PHP page, or link to a PHP script that outputs the image just like a static image. Then you can incerement your hit counter in that script.

    If you are using a database you can do something like this to increment the hit count

    PHP Code:
    // once connected to the DB, obviously

    // $_GET['id'] holds the image ID in the database

    $count = @mysql_result(@mysql_query(
      
    'select distinct `hit_count` from `images` where '.
      
    '`image_id` = '.(int)$_GET['id']
    ), 
    0);

    if (!
    mysql_errno()) {
      
    // the image exists, update the hit count:
      
    mysql_query(
        
    'update `images` set `hit_count` = '.$count++.
        
    ' where `image_id` = '.(int)$_GET['id']
      );
    }
    else {
      
    // throw an error, or whatever

    Note that the @ symbol prepended to a statement suppresses error messages for that statement. It's useful if you have an alternate method of checking for errors, such as mysql_errno() in this case (to handle invalid image IDs), but you should use proper error handling methods otherwise.
    Last edited by penagate; Apr 8th, 2006 at 10:34 AM. Reason: Stupid scrolling bugs in F

Posting Permissions

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



Click Here to Expand Forum to Full Width