homepage Welcome to WebmasterWorld Guest from 54.196.159.11
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Click Counting
field4000




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

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




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

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




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

Agreed with dreamcatcher

dreamcatcher




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

Oops, except that:

$row = mysql_fetch_row($query);

should have been:

$row = mysql_fetch_object($query);

Apologies.

dc

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved