PHP关于日/周/月点击统计代码


PHP #统计2012-04-22 21:23

代码编写的原理就是,先判断当前文章的日期是否为当月当日当周的,是就点击数加1。

$now=time(); //当前时间 
$StrUpdate = "Update $tbl_article set hits=hits+1"; 
if(date("d",$lasthittime)==date("d",$now)){//同一天 
$StrUpdate = $StrUpdate.",dayhits = dayhits+1"; 
}else{ 
$StrUpdate = $StrUpdate.",dayhits = 0"; 
} 
if(date("W",$lasthittime)==date("W",$now)){//同一周 
$StrUpdate = $StrUpdate.",weekhits = weekhits+1"; 
}else{ 
$StrUpdate = $StrUpdate.",weekhits = 0"; 
} 
if(date("m",$lasthittime)==date("m",$now)){//同一月 
$StrUpdate = $StrUpdate.",monthhits = monthhits+1"; 
}else{ 
$StrUpdate = $StrUpdate.",monthhits = 0"; 
} 
$StrUpdate = $StrUpdate.",lasthittime='$now' where id='$id'"; //更新点击时间 
$fsql->query($StrUpdate); 


相关文章

粤ICP备11097351号-1