mrjameer Posted March 31, 2007 Share Posted March 31, 2007 hi, how i can get the total number of times a particular link has been visited.for example:this is the link. www.abcd.com/upload.php?id=761786717.jpg. i want to display how many times this link has been visited thanks mrjameer Link to comment https://forums.phpfreaks.com/topic/45049-how-to-count-the-number-of-times-a-link-is-visited/ Share on other sites More sharing options...
obsidian Posted March 31, 2007 Share Posted March 31, 2007 You have to set up some sort of tracking in your site. Unless you have some sort of analytics software that can offer an API to tap a specific link, you'll have to come up with your own counter. One thing you could do is simply have a table in your database to hold your link and number of visits. Then, when the page loads, just increment the value for the current page in the database. If it doesn't exist, create a record for it and default it to 1. Then, when your page loads, you just hit that table of the DB and pull the current hit count of that page. Hope this helps some. Link to comment https://forums.phpfreaks.com/topic/45049-how-to-count-the-number-of-times-a-link-is-visited/#findComment-218693 Share on other sites More sharing options...
richardw Posted March 31, 2007 Share Posted March 31, 2007 Here is a code snippet that I use and it works in the manner described by obsidian... <?php $query = "SELECT * FROM pagecount WHERE id = 1"; $result = mysql_query($query)or die ("Error in query: $query. "); $row= mysql_fetch_array($result); $cnt = $row["count"]; $cnt++; { <?php { mysql_query( "UPDATE pagecount SET count = '$cnt', WHERE id= 1"); } ?> CREATE TABLE pagecount ( id int(11) NOT NULL auto_increment, count tinyint(5) DEFAULT '1' NOT NULL, page_descriptor text NOT NULL, PRIMARY KEY (id) ); # # Dumping data for table 'pagecount' # INSERT INTO pagecount VALUES ( '1', '1', 'Page To Count'); Add records to the table to count additional pages, but I hope this helps get you going Best Link to comment https://forums.phpfreaks.com/topic/45049-how-to-count-the-number-of-times-a-link-is-visited/#findComment-218701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.