PHP Tutorial : Simple views counter script
Dec 22, 2008 Useful PHP
Hi,
In this php tutorial you will learn the simple way to build a script which counts how many times a page is viewed. For this, we can use a mysql database table and a simple php script.
<?php $pagename = $_SERVER['PHP_SELF']; $sql = "select * from mysqltable where page = '$pagename'"; $rs = mysql_query($sql); if($rs) { $row=@mysql_fetch_object($rs); $counter = $row->counterfield; //update the stats, if they exits $counter = "".($counter+1).""; $qry = mysql_query("updated tablename set counterfield = '$counter' where id = '$row->id'"); }else{ print mysql_error(); } ?>
Tags: count, count views, counter, counter script, number of views, php count, php counter, php views counter, views count, views counter, views script


Leave a Reply