For example, my website wants to count the most popular posts in the last 7 days, that is, the most recent 7-day increase in the number of posts, how to use PHP design, has not been able to think of a good way, I hope you point. In fact, it's like the discuz of hot posts.
Reply content:
For example, my website wants to count the most popular posts in the last 7 days, that is, the most recent 7-day increase in the number of posts, how to use PHP design, has not been able to think of a good way, I hope you point. In fact, it's like the discuz of hot posts.
You can use the Timer function to perform statistics every x hours, and calculate the number of visits, favorites, likes, comments, etc. of posts in the last seven days.
例如: 帖子热度=访问次数*1+收藏*10+点赞*3+评论*5
The result sort is then stored in the data table or cache.
Database design to reflect the increment, before the article table directly add a field to indicate the number of visits. In this case, the access situation should be placed in a single table, each access as a record
Make a self-increment operation based on the article ID redis. Page Display reverse order
Date of posting: time, and number of visits: views. Views increase with the amount of visitors.
Gets the timestamp range of yesterday, before the previous seven days.
public function last_unix($a) { $y = date("Y"); $m = date("m"); $d = date("d")-$a; $start= mktime(0,0,0,$m,$d,$y); $end= mktime(23,59,59,$m,$d,$y); return array('start' =>$start ,'end'=>$end ); }$yesterday = $this->last_unix(1);$lastsevernday = $this->last_unix(7);$hotest=$a->where("time>'$lastsevernday' AND time<'$yesterday'")->max('views');