How to use PHP to count recent popular posts

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