|
|
|
Click
Counter
This tutorial is a bit more difficult then my others because
it requires MySQL. Some coding is needed in the SQL language
and getting access to a Database may prove to be hard, a free
host with MySQL is unheard of, however even the smallest paid
packages usually come with SQL. Im gonna write this tutorial
assumimg you already have minimal knowledge of SQL Databases.
Creat in your database a table named 'clickcounter' with the
properties like the code below.
CODE |
// CREATE TABLE clickcounter (
// id int(11) NOT NULL auto_increment,
// url varchar(50) NOT NULL default '',
// count smallint(3) NOT NULL default '',
// PRIMARY KEY (id)
//) TYPE=MyISAM;
|
Ok, first you will need to make the connection to your
database. Is what this first line does. If u donīt know how
to make the connection to your database i will have a tutorial
up for it soon.
CODE |
<?
include "connection_file.php";
// Youīll call some id in the table through the '$id'
variable.
if (isset($id)){
// Increment the count field value of the requested
id.
$update = mysql_query("UPDATE clickcounter SET
count = count + 1 WHERE id='$id'");
// Select the requested id on the database..
$result = mysql_query("SELECT url FROM
clickcounter WHERE id='$id'");
// Retrieve the data(url) of url field.
$row = mysql_fetch_array($result);
$url = $row[url];
// Redirect to the url and close the database.
header("Location: $url");
}
mysql_close();
?>
|
Thatīs all. Now save this file as click.php.
Call this script making something like this:
click.php?id=10
Example:
This PHP tutorial was clicked 168 times
Tutorial By Xtasy
|
|