Home > Article > Backend Development > Counters and their applications: Three steps to DIY a counter
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 pictures 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<5;$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
);
How about it, easy! In the second part, I will introduce how to make your mirror site use your own counter.
The above has introduced the counter and its application. The three steps of DIY counter creation include the counter and its application. I hope it will be helpful to friends who are interested in PHP tutorials.