Home > Article > Backend Development > Three Steps to Building a Counter DIY (Part 1)_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<5;$i++){
$tmpstr="";
echo $tmpstr;
}
?>
Place the code at the appropriate location on the homepage include "count1.php" ?>, 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.