...

View Full Version : count image views and update db



Chris-2k
07-19-2012, 12:13 AM
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
/********************************

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?

Arcticwarrio
07-19-2012, 08:57 AM
Just create another column in the image table and increment it each time you run your query

something like


$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'");

Chris-2k
07-19-2012, 06:23 PM
Thanks that worked!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum