Home > Article > Backend Development > Three Steps to Making a Counter DIY_PHP Tutorial
Most people are eager to use databases to make their own counters, guestbooks, forums, and the like. This article will introduce my self-made counter program.
First create 10 GIF digital images from 0 to 9, place them in the img folder, and then create a PHP file
——count1.php. The procedure is as follows:
$linkptr= mysql_pconnect("localhost","yourname","password");
mysql_select_db("yourname",$linkptr);
mysql_query("update counter
set visited=visited+1 where num=1" ,$linkptr);
$result=mysql_query("select visited
from counter where num=1",$linkptr);
list($counter)=mysql_fetch_row($result);
$ counter=sprintf("%05d",$counter);
for($i=0;$i $tmpstr="";
echo $tmpstr ;
}
?>
Place the code include "count1.php" ?> at the appropriate location on the homepage, so that your counter will be displayed on the homepage, but remember to create a TABLE on your database - counter: create table counter(
num int unsigned,
visited int unsigned