PHP day week month click ranking statistics
- 2020-05-12 02:19:18
- OfStack
$now=time(); // The current time
$StrUpdate = "Update $tbl_article set hits=hits+1";
if(date("d",$lasthittime)==date("d",$now)){// with 1 day
$StrUpdate = $StrUpdate.",dayhits = dayhits+1";
}else{
$StrUpdate = $StrUpdate.",dayhits = 0";
}
if(date("W",$lasthittime)==date("W",$now)){// with 1 weeks
$StrUpdate = $StrUpdate.",weekhits = weekhits+1";
}else{
$StrUpdate = $StrUpdate.",weekhits = 0";
}
if(date("m",$lasthittime)==date("m",$now)){// with 1 month
$StrUpdate = $StrUpdate.",monthhits = monthhits+1";
}else{
$StrUpdate = $StrUpdate.",monthhits = 0";
}
$StrUpdate = $StrUpdate.",lasthittime='$now' where id='$id'"; // Update click time
$fsql->query($StrUpdate);
I don't know if it's good or not, so let's analyze 1 first
However, it seems that there are some problems, if it is a day, we should judge that the month and month are 1, and then judge the day.