Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:07:09+00:00 2026-06-12T19:07:09+00:00

Every time somebody visits a blog article on my site, I record this in

  • 0

Every time somebody visits a blog article on my site, I record this in a table [blog_article_hits]. Each visit has one row. I now want to display a list of trending articles in the last 14 days, showing the article title and the amount of hits it’s received or a percentage.

Example:

This is a blog article        1,0732
This is another article       930

My Attempt:

SELECT
tre.article_id, COUNT(*) AS total_hits, art.title, art.description,
pho.photo_id
FROM blog_article_stats tre
LEFT JOIN blog_articles AS art ON tre.article_id = art.article_id
LEFT JOIN blog_photos AS pho ON art.article_id = pho.article_id
WHERE tre.d_time BETWEEN DATE_SUB(Now(), INTERVAL 14 DAY) AND Now()
AND pho.status = 'Published' AND art.status = 'Published'
GROUP BY tre.article_id
ORDER BY total_hits DESC LIMIT 5

It’s very close but not quite right. The most popular articles are listed in the correct order but the count next to each title is incorrect. It’s actually showing how many photos there are for each article, not how many times it’s been visited. I thought by having the GROUP BY would help, I even tried adding a secondary GROUP clause on [pho.article_id] but that didn’t help.

I’m selecting [pho.photo_id] and joining [pho.blog_photos], purely because I want to show one photo next to each listed result.

Can anybody advise me on how to resolve this issue?

Many thanks in adv.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:07:11+00:00Added an answer on June 12, 2026 at 7:07 pm

    Change the count to:

    COUNT(DISTINCT tre.PK) AS total_hits
    

    where PK is the primary key of that table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm storing a timestamp in a mysql table every time somebody visits the site
I'm just very curious if somebody has same problem as me. Every time I
Every time I try to access my localhost/phpmyadmin it gives me this error --->
Every time I drag a modified table into my dbml, VS2010 wants me to
I've got a new project. Every time you dealing with somebody else code it's
I run this command every time I build my project from the project directory:
I'm asking this with hopes that somebody has been in my shoes and has
Every time I get something from the db, my code is this: using (SqlConnection
Every time i reset & seed my database it wipes out the standard admin@example.com
Every time when I'm trying to load the .dll in my application, I'm getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.