Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Array having the days as keys (YYYY-mm-dd) and the view count as values */
- $days = array();
- /* Initialize the days keys to 0 */
- for ($i = 0; $i < 7; $i++)
- {
- $dayUts = mktime(0, 0, 0, date('n'), date('j') - $i, date('Y'));
- $day = date('Y-m-d', $dayUts);
- $days[$day] = 0;
- }
- /* Now read the view count from the DB */
- $query = 'SELECT DATE_FORMAT(view_count_date, "%Y-%m-%d") AS time, count(*) AS view_count from ads_view_count WHERE view_count_date >= (NOW() - INTERVAL 7 DAY) AND view_count_user_id = :id';
- /* Note: be sure to validate $_SESSION['id'] */
- $res = $pdo->prepare($query);
- $res->bindValue(':id', $_SESSION['id'], PDO::PARAM_INT);
- $res->execute();
- /* Now we update the $days array with the view count from the query */
- while ($row = $res->fetch(PDO::FETCH_ASSOC))
- {
- if (array_key_exists($row['time'], $days))
- {
- $days[$row['time']] = intval($row['view_count'], 10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement