用PHP和MYSQL建立计数器过程详解
作者:bea
运行MYSQL.EXEmysql> create database counter;Query OK, 1 row affected (0.10 sec)mysql> use counter;Database changedmysql> create table tl(id integer(2),count integer(5));Query OK, 0 rows affected (0.21 sec)mysql> show columns from
运行MYSQL.EXEmysql> create database counter;Query OK, 1 row affected (0.10 sec)
mysql> use counter;Database changed
mysql> create table tl(id integer(2),count integer(5));Query OK, 0 rows affected (0.21 sec)
mysql> show columns from tl;+-------+--------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+--------+------+-----+---------+-------+| id | int(2) | YES | | NULL | || count | int(5) | YES | | NULL | |+-------+--------+------+-----+---------+-------+2 rows in set (0.05 sec)
mysql> select * from tl;Empty set (0.08 sec)
mysql> insert into tl(id,count) values(1,1);Query OK, 1 row affected (0.02 sec)
mysql> select * from tl;+------+-------+| id | count |+------+-------+| 1 | 1 |+------+-------+1 row in set (0.03 sec)
下面编写HTML文件内容:
<html><body>
<?php$myvar = "来访人数:";echo $myvar;?>
<?php mysql_connect() or die("there are problems to connect to mysql!"); $query="select * from tl"; $result=mysql_db_query("counter",$query); if($result){ $r=mysql_fetch_array($result); $counter=$r["count"]; $counter=$counter+1; echo $counter; $query="update tl set count='$counter' where id=1"; $result=mysql_db_query("counter",$query); mysql_close(); }?></body></html>
有用 | 无用
mysql> use counter;Database changed
mysql> create table tl(id integer(2),count integer(5));Query OK, 0 rows affected (0.21 sec)
mysql> show columns from tl;+-------+--------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+--------+------+-----+---------+-------+| id | int(2) | YES | | NULL | || count | int(5) | YES | | NULL | |+-------+--------+------+-----+---------+-------+2 rows in set (0.05 sec)
mysql> select * from tl;Empty set (0.08 sec)
mysql> insert into tl(id,count) values(1,1);Query OK, 1 row affected (0.02 sec)
mysql> select * from tl;+------+-------+| id | count |+------+-------+| 1 | 1 |+------+-------+1 row in set (0.03 sec)
下面编写HTML文件内容:
<html><body>
<?php$myvar = "来访人数:";echo $myvar;?>
<?php mysql_connect() or die("there are problems to connect to mysql!"); $query="select * from tl"; $result=mysql_db_query("counter",$query); if($result){ $r=mysql_fetch_array($result); $counter=$r["count"]; $counter=$counter+1; echo $counter; $query="update tl set count='$counter' where id=1"; $result=mysql_db_query("counter",$query); mysql_close(); }?></body></html>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- Apache2的httpd.conf翻译
- Linux下安装GD
- 用ActivePHP打造版本管理系统
- Smarty实例教学 实例篇
- php实现首页自动选择语言转跳
- 使用php通过Socket进行发信源码,支持发信认证
- PHP应用分页显示制作详细讲解
- 令你的网站获得任意Google PR值的方法
- PHP和JAVA的XML-RPC中文问题解决办法
- 解决RHAS3中Apache2的PHP上传文件大小的限制
- 用php发送带附件的Email
- 用php实现gb2312和unicode间的编码转换
- PHP编实现程动态图像的创建
- 利用Yahoo! Search API开发自已的搜索引擎-php版
- 用PHP实现标准的IP Whois查询
- PHP巧获服务器端信息
- 搜索引擎核心技术(PHP编程思路) --[1]
- PHP 脚本:随心所欲的代码逐渐流行
- 简单设置IIS配置PHP调试环境