Jump to content

how to count the number of times a link is visited


mrjameer

Recommended Posts

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.

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  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.