PDA

Click to See Complete Forum and Search --> : Count the Clicks


stickman373
Dec 4th, 2002, 07:07 PM
How do I keep track of and record the # of clicks on a certain link?

thanks :)

The Hobo
Dec 4th, 2002, 10:27 PM
The easiest way would be to use a MySQL database over flat file.

Have your link like this: http://www.site.com/tracker.php?link=http://www.site.com/about.php

Then do something like:

mysql_connect(...);
$results = mysql_query("SELECT ... WHERE sitename='" . $_REQUEST['link'] . "'");

if ($result = mysql_fetch_array($results)) {
//exists in database already. update:
$count = $result['hits'] + 1;
mysql_query("UPDATE ... SET hits='$count' WHERE ...");
} else {
//does not exist. add new entry:
myql_query("INSERT ... (site, hits) VALUES ('" . $_REQUEST['link'] . "', '1'");
}

header("Location: " . $_REQUEST['link']);

Something along those lines. Note that that's all psuedocode off the top of my head and wont automatically work. You need to create the table and fill in a few blanks.

Hope this helps. :)

stickman373
Dec 5th, 2002, 10:45 AM
alright i get the basic idea, thanks;)