php统计代码行数据 php统计源码

如何用PHP统计mysql数据表里指定字段的内容的总数mysql_connect("localhost","root","123456") or
die("打开数据库服务器失败!");//连接数据库
mysql_select_db("a") or
die("打开数据库a失败!");//打开数据库,a为数据库名
$sql = "select id from b";//id为字段名,b为表名
$result=mysql_query($sql);
if(mysql_query($sql))//判断$sql语句是否执行
{
$num=mysql_num_rows($result);//取得包含id字段记录的行数
echo "一共有".$num."个id"; }思想就是:根据含有ID的记录(数据库里一行内容称为一条记录)条数来确定ID的个数
php流量统计功能的实现代码流量统计功能
显示效果:
总访问量:399
今日流量:14
昨日流量:16
本代码仅供学习交流 , 其中必有不妥之处 。请见谅!
--
--
表的结构
`mycounter`
--
复制代码
代码如下:
CREATE
TABLE
`mycounter`
(
`id`
int(11)
NOT
NULL
auto_increment,
`Counter`
int(11)
NOT
NULL,
`CounterLastDay`
int(10)
default
NULL,
`CounterToday`
int(10)
default
NULL,
`RecordDate`
date
NOT
NULL,
PRIMARY
KEY
(`id`)
)
ENGINE=InnoDB
DEFAULT
CHARSET=gbk
AUTO_INCREMENT=2
;
函数过程如下:
复制代码
代码如下:
?PHP
public
function
ShowMyCounter(){
//定义变量
$IsGone
=
FALSE;
//读取数据
$querysql
=
"SELECT
*
FROM
`mycounter`
WHERE
id
=
?'
";
$queryset
=
mysql_query($querysql);
$row
=
mysql_fetch_array($queryset);
//获得时间量
$DateNow
=
date('Y-m-d');
$RecordDate
=
$row['RecordDate'];
$DateNow_explode
=
explode("-",$DateNow);
$RecordDate_explode
=
explode("-",$RecordDate);
//判断是否已过去一天
if(
$DateNow_explode[0]
$RecordDate_explode[0])
$IsGone
=
TRUE;
else
if(
$DateNow_explode[0]
==
$RecordDate_explode[0]
){
if(
$DateNow_explode[1]
$RecordDate_explode[1]
)
$IsGone
=
TRUE;
else
if(
$DateNow_explode[1]
==
$RecordDate_explode[1]
){
if(
$DateNow_explode[2]
$RecordDate_explode[2]
)
$IsGone
=
TRUE;
}else
BREAK;
}else
BREAK;
//根据IsGone进行相应操作
IF($IsGone)
{
$RecordDate
=
$DateNow;
$CounterToday
=
0;
$CounterLastDay
=
$row['CounterToday'];
$upd_sql
=
"update
mycounter
set
RecordDate
=
'$RecordDate',CounterToday
=
'$CounterToday',CounterLastDay
=
'$CounterLastDay'
WHERE
id
=
?'
";
mysql_query($upd_sql);
}
//再次获取数据
$querysql
=
"SELECT
*
FROM
`mycounter`
WHERE
id
=
?'
";
$queryset
=
mysql_query($querysql);
$Counter
=
$row['Counter'];
$CounterToday
=
$row['CounterToday'];
$CounterLastDay
=
$row['CounterLastDay'];
if($row
=
mysql_fetch_array($queryset)
【php统计代码行数据 php统计源码】){
if(
$_COOKIE["user"]
!=
"oldGuest"
){
$Counter
=
++$row['Counter'];
$CounterToday
=
++$row['CounterToday'];

推荐阅读