Jump to content

Most Viewed (this week) (this month)


postalservice14

Recommended Posts

I am trying to implement a Most Viewed this week this month function for my web site.  My database is setup as follows:

PAGE
  page_id
  topic

PAGE_VISITS
  visits_id
  page_id
  timestamp

Everytime someone visits a page, it gets logged with the page_id and timestamped in the PAGE_VISITS table of the DB.

What I want to do is return the N number of "most visited" pages.  And I thought this DB structure would be the best way to do it...Am I wrong?  I gotta say I'm stumped now.  Is there some crazy SQL statement I can do?

Thanks in advance.

John
Link to comment
Share on other sites

Ok quick example... (only for month), but you can use (between, interval) and many different options, it all depends on what you want the result to show...

// top 3 pages for 11 month of 2006

[code]SELECT p.page_id, COUNT(v.visits_id) AS total FROM PAGE AS p
LEFT JOIN PAGE_VISITS AS v ON(p.page_id = v.page_id)
WHERE MONTH(`v.timestamp`) = 11 AND YEAR(`v.timestamp`) = 2006 ORDER BY total DESC LIMIT 3;[/code]

As I said there are hundreds of different formats, it depends on what exactly you want to display...

printf
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.