|
|
| YOUR HIT COUNTER IN PHP |
|
I will in this tutorial show you how to make a hit counter, using a
MySQL database.
|
Making the Hit-counter
|
|
When a user enters your site, you have to update the table in your database. I have called
my table for tbHits and the database for dbHits. If you are not familiar to the connect
functions or the SQL statements, this tutotrial will show you the basics.
|
//connecting to the db
$host = "localhost";
$username = "apron";
$password = "apron123";
$database = "dbHits";
$server = mysql_connect($host, $username, $password);
$connection = mysql_select_db($database, $server);
//get the recordset with SQL
$rs = mysql_query("SELECT * FROM tbHits");
$viewers = 0;
//update the table
if($row=mysql_fetch_assoc($rs))
{
$viewers = $row[Viewers] + 1;
}
//update the tbHits table
$sql = mysql_query("UPDATE tbHits SET Viewers = '$viewers'");
//close the db connection
mysql_close($server);
//display the viewers
echo($viewers);
|
|
Category
|
Programming with PHP
|
|
Author
|
Tommy Johannessen
|
|
|
|