For example, my website wants to count the most popular posts in the last seven days, that is, the most frequently accessed posts in the last seven days. I have never been able to figure out a good way to use php design, I hope you can give me some advice. In fact, it is similar to discuz's hot posts. for example, my website wants to count the hot posts in the last seven days, that is, the posts with the most visits in the last seven days. how should I use php to design them, I have never been able to find a good solution. I hope you can give me some advice. In fact, it is similar to the features of discuz hot posts
Reply content:
For example, my website wants to count the most popular posts in the last seven days, that is, the most frequently accessed posts in the last seven days. I have never been able to figure out a good way to use php design, I hope you can give me some advice. In fact, it is similar to the features of discuz hot posts
You can use the timing function to perform statistics every X hours, and calculate the number of visits, favorites, likes, and comments of the posts in the last seven days.
For example: Post popularity = number of visits * 1 + favorites * 10 + likes * 3 + comments * 5
Then, the results are sorted to the data table or cached.
During database design, incremental data must be reflected. in the past, a field was directly added to the document table to indicate the number of visits. in this case, the access should be stored in a single table, and each access should be used as a record.
Perform the auto-increment operation based on the article ID redis. Page display in reverse order
The posting time, browsing times, and views are recorded in the data table. Views increase with the number of views.
Obtain the timestamp range of 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');