How to use php to count recent hot posts

Source: Internet
Author: User
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');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.