I am currently writing my own CMS system in PHP.
All views of a post should be stored in the MySQL database every day.
Currently I have a view counter, which stores all post views of a post in the post table.
$article_id = $_GET['p_id'];
// article view counter
$view_query = "UPDATE articles SET article_views_count = article_views_count + 1 WHERE article_id = $article_id ";
$send_query = mysqli_query($connection, $view_query);
Now I want to change the whole thing that every day for each post a new entry is made in a separate table.
I've learned how to do it all, but my current SQL command adds a new entry to the table each time it's called, not counting for the whole day.
The new SQL-Command:
INSERT INTO days_views (`article_id`, `day_views_count`, `day`) VALUES (1, 1, CURDATE()) ON DUPLICATE KEY UPDATE `day_views_count` = `day_views_count` + 1;
CREATE TABLE `days_views` (
`day_views_id` int(11) NOT NULL,
`article_id` int(11) NOT NULL,
`day_views_count` int(255) NOT NULL,
`day` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_german2_ci;
ALTER TABLE `days_views`
ADD PRIMARY KEY (`day_views_id`);
ALTER TABLE `days_views`
MODIFY `day_views_id` int(11) NOT NULL AUTO_INCREMENT;
How can I add one row every day for every post?
How can I count the views for the whole day?