超简单的php图片统计器,这种统计器以前我是用txt文件做的,现在就直接用数据库实现吧.先来看看数据结构吧.
- CREATE TABLE `count` (
- `id` int(10) NOT NULL auto_increment,
- `value` varchar(20) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=98 ;
数据准备好了下面我们来看看程序是怎么实现的吧.
- <?php
-
- $conn=mysql_connect("localhost","root","root");
-
- mysql_query("set names gb2312");
- mysql_select_db("guest");
- $sql="INSERT INTO `count` ( `id` , `value` ) VALUES ('', '32')";
- $result=mysql_query($sql);
- if ($result) {
- echo "插入成功.";
- }
- mysql_close($conn);
-
-
-
- $conn=mysql_connect("localhost","root","root");
-
- mysql_query("set names gb2312");
- mysql_select_db("guest");
- $mysql="select * from `count`";
-
- $result=mysql_query($mysql);
- $row=mysql_num_rows($result);
- for($i=0;$i<strlen($row);$i++)
- {
- $a=substr($row,$i,1);
- $str.= "<img src= "images/$a.jpg" width="32" height="32" />";
- }
- ?>
- <div align="center" class="STYLE1">页面总共有<?php echo $str; ?>个人浏览</div>
嗯,php代码写得有一点乱喽,但工能还是能实现的吧. |