Forum Moderators: coopster
I have a links directory that I would like to count the number of times a link is clicked.
I currently have all the links being displayed by pulling the links data from a MySQL table. I have added the a 'Count' field to the existing table. The table contains the following fields: LinkID, Category, Name, URL, Description, Count.
My question is is it possible to count the clicks once the links data has been printed to HTML? I am thinking of the PHP equivalent of OnClick Count = Count + 1. Or have I got the whole logic back to front?
Cheers.
[yoursite.com...]
//Assign the variable
$track = $_GET['track'];//Get URL from database
$query = "SELECT url FROM table WHERE id = '$track' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_row($query);//Update count
mysql_query("UPDATE table SET count=(count+1) WHERE id = '$track' LIMIT 1") or die(mysql_error());Redirect to URL
header("Location: $row->url");
Hope that helps.
dc