Monday, 20 July 2015

Make simple page counter using php and mysql


A hit counter or a page counter counts the number of people that visit your page. If you have created a new website you might be interested how many people are visiting. so try this simple method count how many people visit on your website. this coding make MySQL update query using in php.





Database
Create count table and insert sample value in name field to the database. Ex; Name="Mostlikers" don't insert count value watch below table coding


CREATE TABLE Count
(
id INT  AUTO_INCREMENT,
Name TEXT
count INT
);
Count.php
Create count.php page Fetch database count table value from this page using below coding update through
page count value will be increased.

<?php
$fetch=mysql_query("select * from count");
while($row1=mysql_fetch_array($fetch))
{

    $id=$row1['id'];
    $samplename=$row1['name'];
    $counts=$row1['count'];
    $tolcount2=$counts+1;
    $updates=mysql_query("update count set count='$tolcount2' where id='$id' ");
}
?>

Fetch the count value using increment value +1 to update the database from given value
out.php
Refresh count.php file value will be increased show as output below

 <span style="color:#F00;">(<?php echo $tolcount2; ?>)</span>

0 comments:

Post a Comment