PHP 日,周,月点击排行统计

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

$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);

不知道好不好用啊,先分析一下再说了
不过感觉好像有些问题,如果是天的应该先判断年月都是一样的,然后再判断天。

相关文章

php strtotime 函数UNIX时间戳

如果 time 的格式是绝对时间则 now 参数不起作用。如果 time 的格式是相对时间则其所相对的时间由 now 提供,或者如果未提供 now 参数时用当前时间。失败时返回 -1。...

PHP 杂谈《重构-改善既有代码的设计》之一 重新组织你的函数

PHP 杂谈《重构-改善既有代码的设计》之一 重新组织你的函数

思维导图 点击下图,可以看大图。 介绍 我把我比较喜欢的和比较关注的地方写下来和大家分享。上次我写了篇《php 跟老大的对话》。还是有很多疑问,这书帮了我不少的忙。 如果你比较繁忙,或者...

PHP mb_convert_encoding 获取字符串编码类型实现代码

后来又在手册上找到了is_utf8函数,这样,再结合iconv函数,我的问题就解决了。下面帖出这个函数: 复制代码 代码如下:function is_utf8($string) { re...

Sorting Array Values in PHP(数组排序)

复制代码 代码如下: $full_name = array(); $full_name["Roger"] = "Waters"; $full_name["Richard"] = "Wri...

PHP加密解密字符串汇总

项目中有时我们需要使用PHP将特定的信息进行加密,也就是通过加密算法生成一个加密字符串,这个加密后的字符串可以通过解密算法进行解密,便于程序对解密后的信息进行处理。 最常见的应用在用户登...