Current location: Hot Scripts Forums » Programming Languages » PHP » Counting Image Views


Counting Image Views

Reply
  #1 (permalink)  
Old 12-21-04, 07:54 AM
thesoj thesoj is offline
New Member
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Counting Image Views

I have a whole bunch of images, and I want to know how many times each have been viewed.

But the trick is, that I need to update a mysql db, with the info, say when someone accesses:
www.mysite.com/myimage.gif

I need to update it using a PHP script, but I don't know how I'd go about it.

I can't figure it out, I also tried to do it with a php script, like:
www.mysite.com/img.php?i=myimage.gif

But failed miserably at it.

Any help would be greatly appreciated.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-21-04, 10:18 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
using a php script is the sulotion ..
something like that:
PHP Code:

<?PHP

$ID 
= (int)$_GET['ID'];

/* DO MySQL CONNECTION HERE */

$fetch mysql_query("SELECT * FROM image_table WHERE ID='$ID'")or
die(
mysql_error());

$num mysql_num_rows($fetch);

if (empty(
$num))
   
$fullname 'path/to/default_error.png';
else {
   
$images mysql_fetch_assoc($fetch);

   
$image $images['imagename'];
   
$path  $images['imagepath'];

   
$fullname "$path/$image";

   
mysql_query("UPDATE image_table SET counter=counter+1 WHERE ID='$ID'")or
   die(
mysql_error());
}

$fp fopen($fullname'r');
$read fread($fpfilesize($fullname));
fclose($fp);
die(
$read);
?>
and to get the pictures use:
Code:
<img src="image.php?ID=25" alt"" />
or you could use the file name instead of the ID
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-21-04, 04:48 PM
thesoj thesoj is offline
New Member
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Alot

That just about did it, although I needed to change a few things.

Thank you very much.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
searching image nurqeen PHP 4 07-09-05 10:35 AM
Image upload and if / else mdhall PHP 4 11-14-04 04:12 PM
Help with image on form... Adrianaa03 JavaScript 1 10-06-04 08:38 AM
how to draw an image inside a table? davidklonski HTML/XHTML/XML 2 07-06-04 11:27 AM
need help with upload image and getting image name to db mikewooten PHP 3 05-14-04 05:52 PM


All times are GMT -5. The time now is 12:21 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.