Answer the question
In order to leave comments, you need to log in
Proper storage of statistics, and work with it with high attendance?
Good afternoon dear!
Not so long ago, I implemented modest statistics for the account of news views for the site. I use MySQL for storage.
As a result, I got a pretty simple table:
CREATE TABLE `developers_stat` (
`news_id` int(20) DEFAULT NULL,
`date` date DEFAULT NULL,
`views` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
news_id | date | views
4285 | 2016-12-29 | 8258
4285 | 2016-12-10 | 10698
4285 | 2016-12-11 | 10989
4285 | 2017-01-02 | 11735
4285 | 2017-01-07 | 11253
$readcount_stat = $db->super_query( "SELECT count(*) as count FROM developers_stat WHERE news_id='{$row['id']}' AND date='{$today}'" );
if( !$readcount_stat['count'] ) {
$db->query( "INSERT INTO developers_stat (news_id, date, views) VALUES ('{$row['id']}', '{$today}','1')" );
}else{
$db->query( "UPDATE developers_stat SET views=views+1 WHERE news_id='{$row['id']}' AND date='{$today}'" );
}
news_id | total_views
4283 | 301894
4284 | 380036
4285 | 250481
news_id | date | views
4283 | 2017-01-02 | 11735
4283 | 2017-01-03 | 12248
4284 | 2017-01-04 | 11804
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question