打造计数器DIY三步曲(上)
更新时间:2006年10月09日 00:00:00 作者:
人大多都很向往使用数据库来做自己的计数器,留言本,论坛之类的东西了,本篇将介绍本人自制的计数器程序。
首先建立0~9这10个GIF数字图片,放在img文件夹下,再建立一个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;
}
?>
在主页上适当位置放置代码<? include "count1.php" ?>,这样主页上就显示了你的计数器,不过要记住在你的数据库上建立一个TABLE——counter:create table counter(
num int unsigned,
visited int unsigned
);
怎么样,容易吧!中篇我将介绍怎样让你的镜像站也能用上你自己的计数器。
首先建立0~9这10个GIF数字图片,放在img文件夹下,再建立一个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;
}
?>
在主页上适当位置放置代码<? include "count1.php" ?>,这样主页上就显示了你的计数器,不过要记住在你的数据库上建立一个TABLE——counter:create table counter(
num int unsigned,
visited int unsigned
);
怎么样,容易吧!中篇我将介绍怎样让你的镜像站也能用上你自己的计数器。
相关文章
PHP中基于ts与nts版本- vc6和vc9编译版本的区别详解
本篇文章介绍了,PHP中基于ts与nts版本- vc6和vc9编译版本的区别详解。需要的朋友参考下2013-04-04PHP学习之输出字符串(echo,print,printf,print_r和var_dump)
在PHP中,有四种方法输出字符串。echo结构可以一次输出多个值;print()只可以输出一个值;printf()可以格式化输出;print_r()可以输出数组,对调试很有好处。2011-04-04
最新评论