Creating a click counter is pretty simple. All it requires is after the code has
been trigger, to add 1 to the given row. Sound easy enough?
The fields being used here are count, which can be inserted as a
"SMALLINT(3) NOT NULL", url which can be "VARCHAR (50) NOT NULL", and
lastly ID which depending upon your already installed script is up to
you. Count is where the number of times a url has been clicked is stored, URL is
where the page then redirects to.
<?
#Just some information to be filled out.
#Given table for the code to communicate with.
$table="blah";
#Server where the database is located.
$dbhost="localhost";
#Name to connect to the database.
$dbname="name";
#Password to verify its you.
$dbpass="*****";
#Database to connect with within the sever.
$dbbase="base";
//Now to connect to mySQL.
$connect = mysql_connect("$dbhost", "$dbname", "$dbpass");
mysql_select_db($dbbase, $connect);
//Updates the field "count" where the given
//row was specified, in this case by it's ID.
$update = "UPDATE $table SET count = count + 1, url = url WHERE id='$id'";
$result = mysql_query($update);
//After it added the click it then redirects to the URL.
$query = "SELECT * FROM $table WHERE id='$id'";
$result = mysql_query($query);
$tab=mysql_fetch_array($result);
$url=$tab["url"];
header("Location: $url");
?>
One thing to keep in mind is on line 23: $update = "UPDATE $table SET count = count + 1, url = url WHERE id='$id'";
I restated the other fields. I would suggest on doing that for all
variables(fields). IE you would not have to reinsert ID, though this is just to
lessen any confusion. And that's it. You can access it by start to linking sites
by http://yoururlhere.com/?id=45 (45 being a variable). Though now you may be
wondering what the hell am i going to use that for? If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.