打造計(jì)數(shù)器DIY三步曲(上)
更新時(shí)間:2006年10月09日 00:00:00 作者:
人大多都很向往使用數(shù)據(jù)庫來做自己的計(jì)數(shù)器,留言本,論壇之類的東西了,本篇將介紹本人自制的計(jì)數(shù)器程序。
首先建立0~9這10個(gè)GIF數(shù)字圖片,放在img文件夾下,再建立一個(gè)PHP文件
——count1.php,程序如下:
<?
$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="<img src=img/".substr($counter,$i,1).".GIF >";
echo $tmpstr;
}
?>
在主頁上適當(dāng)位置放置代碼<? include "count1.php" ?>,這樣主頁上就顯示了你的計(jì)數(shù)器,不過要記住在你的數(shù)據(jù)庫上建立一個(gè)TABLE——counter:create table counter(
num int unsigned,
visited int unsigned
);
怎么樣,容易吧!中篇我將介紹怎樣讓你的鏡像站也能用上你自己的計(jì)數(shù)器。
首先建立0~9這10個(gè)GIF數(shù)字圖片,放在img文件夾下,再建立一個(gè)PHP文件
——count1.php,程序如下:
<?
$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="<img src=img/".substr($counter,$i,1).".GIF >";
echo $tmpstr;
}
?>
在主頁上適當(dāng)位置放置代碼<? include "count1.php" ?>,這樣主頁上就顯示了你的計(jì)數(shù)器,不過要記住在你的數(shù)據(jù)庫上建立一個(gè)TABLE——counter:create table counter(
num int unsigned,
visited int unsigned
);
怎么樣,容易吧!中篇我將介紹怎樣讓你的鏡像站也能用上你自己的計(jì)數(shù)器。
相關(guān)文章
用IE遠(yuǎn)程創(chuàng)建Mysql數(shù)據(jù)庫的簡易程序
用IE遠(yuǎn)程創(chuàng)建Mysql數(shù)據(jù)庫的簡易程序...2006-10-10用Php實(shí)現(xiàn)鏈結(jié)人氣統(tǒng)計(jì)
用Php實(shí)現(xiàn)鏈結(jié)人氣統(tǒng)計(jì)...2006-10-10PHP個(gè)人網(wǎng)站架設(shè)連環(huán)講(一)
PHP個(gè)人網(wǎng)站架設(shè)連環(huán)講(一)...2006-10-10