Jump to content

Non-Noob question. Counter setup


sprintlife

Recommended Posts

Hey IT programmers,

 

I've been looking an basic setup for a counter system. I have a few different categories of items that I want to show it's hit rate. For example I wanna break it down like today's top hits (daily), past 7 days hits (weekly), Past 30 days (monthly), and total hits in all. My question is how should I record the data. Setup a table that records each hit and date it OR should I add 4 colums at the end of the items table so show daily, weekly, monthly, and total?

 

If this question has been posted before sorry you may delete it, but just point me in the area where it's at.

 

All I am trying to do is go with the best setup.

 

Thanks

~Sprintlife

 

Link to comment
Share on other sites

A DB table, or tables would be the way to go. I would suggest you use your lowest common denominator. If you wanted total hits, monthly hits, and daily hits, then your lowest is days. So, make your table with two columns; date and count. Then every time someone hits it, you can increment that day. Like this:

 

$query = "SELECT \"count\" FROM hit_counter WHERE \"date\" = '".date('Y-m-d')."'";
// If you get a result, do an update. Otherwise do an insert

// then you can do one of three selects:

// for one day
$query = "SELECT \"count\" FROM hit_counter WHERE \"date\" = '$date'";

// for one month
$query = "SELECT SUM(\"count\") FROM hit_counter WHERE \"date\" BETWEEN '$startdate' AND '$enddate'";

// total
$query = "SELECT SUM(\"count\") FROM hit_counter";

Link to comment
Share on other sites

Thanks F1Fan for the fast reply.

 

I believe you have helped me make up my mind on it.  Let me break it down a little bit more.  I have few 100  lets call them "items".  I want a table on the homepage of the user's page showing what is the top 5 most viewed for the past day, then past 7 days, then past 30 days.  So basically I need to setup another table contenting the following ( id, item id, time ).  I just kind of worry doing that much pull from the database.  Like if I had 10,000 users at once pulling that much data at a time.  Should I need worry?

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.