...

View Full Version : Count the clicks



Bengal313
03-25-2003, 08:48 PM
I have a site that is full of pictures that people can download. (Wallpapers). What I need is somehow be able to have a page where you can click the link to downlaod the pic. But also on the same page some where near the link have a box that contains the number of times that link have been clicked on. Does anyone know how this can be done?

Spookster
03-25-2003, 09:08 PM
Take your pick:

http://www.hotscripts.com/PHP/Scripts_and_Programs/Click_Tracking/

missing-score
03-25-2003, 09:19 PM
Create a table with 2 columns, Linkid and Clicks.

You need to edit the link to the download page and make sure there is a ?id=NUMBER on the end, Ill explain later.


<?php

$db = @mysql_connect('localhost','user','pass') or die(mysql_error());
@mysql_select_db('dbname',$db);

$getCurrentAmt = "SELECT * FROM `new_table_name` WHERE Linkid='".$_GET['id']."';";
$num = @mysql_query($getCurrentAmt);
$amt = @mysql_num_rows($num);

$sql_query = "UPDATE `new_table_name`
SET `Clicked`= '".($amt+1)."'
WHERE Linkid='".$_GET['id']."';";
@mysql_query($sql_query);

?>


This code updates the database. You need each of your images to have an id, and insert all of them into the database. When you link to the download page, make sure you have the id=ImageId after the link ( eg. download.php?id=1 )

Then to display the amount of times clicked, use this simple function:


<?php

function getClicks($linkid)
{
// YOU DONT NEED THIS IF YOU ARE ALREADY CONNECTED TO YOUR DATABASE
$db = @mysql_connect('localhost','user','pass') or die(mysql_error());
@mysql_select_db('dbname',$db);
// YOU DONT NEED THIS IF YOU ARE ALREADY CONNECTED TO YOUR DATABASE


$que = "SELECT * FROM `new_table_name` WHERE Linkid='".$linkid."';";
$get = mysql_query($que);
$row = mysql_fetch_row($get);

return $row['Clicks'];

}

?>

You could use the function like this:


$clicks = getClicks(1);
echo $clicks;



Hope this helps. If you need it explaining I will help you some more.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum