简体   繁体   中英

Best way to update view count in PHP/MySQL

My client has a table that tracks total views for each of his articles. The problem is they want me to break the view count into days. I can easily enough query the db and grab the view counts, but I'm unsure of how to grab each days view count (for each article of course).

In case I'm not being clear (which is usually the case I've been told) I have a field in a table that collects all views on each article with no regard to date or time. If the article was viewed, the row is plus one'd. Look at the record a year from now and the view count shows 2,000. That's it.

What I want to do is capture each days view count for each article and plunk that into its own table but I CANNOT impact said view count field/record. This way, the client can view each days view count on each article. Any idea on the best approach?

I hope that all made sense!!

如果您是我,则将为视图创建一个新表,并在每个视图上以及在何时查看该视图时插入一条新记录,然后我将选择今天过时的所有视图并对其进行计数,这将使我获得查看次数。该文章今天已被查看,并且仍将保持总数

Something like:

INSERT INTO `daily_views` SET `views` = 
    SELECT COUNT(*) FROM `views_table` 
    WHERE `date` BETWEEN '2013-06-10' 
    AND '2013-06-11'
    AND `post_id` = 1
, `post_id` = 1;

Start at New Year Eve. Each day take the count and store it in a separate table. On the next day subtract current count with the stored one - this is yesterday's count - store the difference on another table together with the date. So, clear or not?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM