Welcome to WebmasterWorld Guest from 54.167.58.159

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Click Counting

     

field4000

4:09 am on Jul 19, 2005 (gmt 0)

10+ Year Member



Hey all,

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.

dreamcatcher

6:56 am on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You`re on the right track. The syntax you have is correct for MySQL, so you would do something like:

[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

webvand

11:36 am on Jul 19, 2005 (gmt 0)

10+ Year Member



Agreed with dreamcatcher

dreamcatcher

1:15 pm on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Oops, except that:

$row = mysql_fetch_row($query);

should have been:

$row = mysql_fetch_object($query);

Apologies.

dc