I save the timestamp in the mysql table every time someone visits the site for the first time.
I wrap up with data that looks like this:
2009-08-02 04:08:27
2009-08-02 04:07:47
2009-08-02 05:58:13
2009-08-02 06:28:23
2009-08-02 06:34:22
2009-08-02 08:23:21
2009-08-02 09:38:56
What I want to do with this data, create the number of visits that fall in every hour. So, in the example above, I will arrive at the 4th hour, having 2 visits, 5th hour = 1, 6th hour 2, 8th hour 1, etc.
I thought the best way to do this is to do this:
for($i = 24; $i > -1; $i--) {
$sql = 'SELECT * FROM visits WHERE (DATE(added) = DATE_SUB(CURRENT_DATE(), INTERVAL ' . $i . ' HOUR))'
$res = mysql_query($sql);
$count = mysql_num_rows($res);
$visits[] = $count;
}
This seems logical to me ... but for some reason ... its definitely not working.
How do you do this?
source
share