Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 2nd Jul 2013, 02:41 PM   #1
Warrior Member
 
Join Date: 2013
Location: Bristol
Posts: 10
Thanks: 1
Thanked 4 Times in 2 Posts
Default
Get average hits (day, week, month) with SQL/PHP
Share on: 
fb share twitter share gplus share more share

Hey all

Does anybody know how to work out average hits per day, week and month based on UNIX timestamps?

Basically I want to track users time on my site and average hits for analytics (I know I can do this in Google Analytics, but I've built some blogging software for personal use and want some basic analytics). I've already worked out how to calculate average time on my site with my data.

I have a table in MySQL with the following format:

Note "start" and "end" are UNIX timestamps.
Code:
+----------------+----------------+----------------+----------------+
| start          | end            | unique_id      | id             |
+----------------+----------------+----------------+----------------+
| 1358789867     | 1358789872     | (hash here)    | 65             |
+----------------+----------------+----------------+----------------+
| 1358789966     | 1358789972     | (hash here)    | 66             |
+----------------+----------------+----------------+----------------+
| 1358789998     | 1358790003     | (hash here)    | 67             |
+----------------+----------------+----------------+----------------+
Would appreciate some input.

Cheers.

Join 15,000+ other Android fans on my Facebook @ Droids R Us
Also join me at Texo digital
Texo is offline  
Unread 3rd Jul 2013, 06:21 AM   #2
Howdy
War Room Member
 
Valdor Kiebach's Avatar
 
Join Date: 2008
Location: England
Posts: 683
Thanks: 103
Thanked 150 Times in 124 Posts
Default
Re: Get average hits (day, week, month) with SQL/PHP
Share on: 
fb share twitter share gplus share more share

Are you going to log the amount of visitors in a time range or will it be the individual time for every visitor.

Your first row in your example is a 5 minute period so are you counting x visitors per 5 minute period.
Valdor Kiebach is offline  
Unread 3rd Jul 2013, 10:46 AM   #3
Warrior Member
 
Join Date: 2013
Location: Bristol
Posts: 10
Thanks: 1
Thanked 4 Times in 2 Posts
Default
Re: Get average hits (day, week, month) with SQL/PHP
Share on: 
fb share twitter share gplus share more share

I'm logging the UNIX timestamp for when they land on any page on my site, and logging the UNIX timestamp for when they leave (close the browser or navigate away, updated via AJAX), so I'm not using any time frames, simply the length of time each individual is on my site.

To calculate the hits I know I can just use the "start" time, but I don't know how to extract the data I want or which functions could help.

Your post is appreciated!


Thank you.

Join 15,000+ other Android fans on my Facebook @ Droids R Us
Also join me at Texo digital
Texo is offline  
Unread 3rd Jul 2013, 12:25 PM   #4
digital carpenter
War Room Member
 
brutecky's Avatar
 
Join Date: 2013
Location: Pennsylvania
Posts: 1,306
Thanks: 480
Thanked 747 Times in 444 Posts
Default
Re: Get average hits (day, week, month) with SQL/PHP
Share on: 
fb share twitter share gplus share more share

Originally Posted by Valdor Kiebach View Post

Are you going to log the amount of visitors in a time range or will it be the individual time for every visitor.

Your first row in your example is a 5 minute period so are you counting x visitors per 5 minute period.
If Im not mistaken UNIX times tamps are the number of seconds since 1/1/1970 so the first row is a 5 second period not a 5 minute.


To work out averages you can

1) take the start date / end date convert time to a time stamp with strtotime()
2) grab all the entries with a start time within that range
3) count the entries
brutecky is offline  
Unread 3rd Jul 2013, 04:07 PM   #5
Howdy
War Room Member
 
Valdor Kiebach's Avatar
 
Join Date: 2008
Location: England
Posts: 683
Thanks: 103
Thanked 150 Times in 124 Posts
Default
Re: Get average hits (day, week, month) with SQL/PHP
Share on: 
fb share twitter share gplus share more share

Originally Posted by brutecky View Post

If Im not mistaken UNIX times tamps are the number of seconds since 1/1/1970 so the first row is a 5 second period not a 5 minute.
Indeed, my mistake.
Valdor Kiebach is offline  
Closed Thread


Bookmarks

Tags
average, day, hits, month, sql or php, week


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 08:48 AM.