How can I make this #Array Sample# look like the #End Result Array#? I am making a google graph for hourly views. Below is an example of my array from the database and it needs to be summarized to counts per hour and if there are no hits per hour it needs to maintain a 0 for that hour so the graph is accurate. And the ID is for a specific page so I have to loop this again.
Wow Anthony, yep that works perfect! I was testing the range(0,23) idea but yours has better scalability with the Gregorian date feature I think. Thanks a ton! You have helped out tremendously.
Actually Anthony, that is much cleaner to do that in mysql. Now, I am still trying to figure out how to find the hours with no results so they can have 0 on the chart. Without the 0 for those empty hours the chart isn’t very accurate. So I have to be able to see where there is inactivity. I think I am only going to pull 1 day of data at a time so I can probably just loop $i++ till it hits 23.
Here is a sample from your query once I inserted that.
Hi Anthony, thanks for the reply! So far I have this which sums up the counts for the interval. I am a little confused on how to get the hours with 0 into the array since they don’t exist in the original result. Also the key is the day-hour which I think might be fine.
# Divide into intervals
$interval_array = array();
foreach($result as $interval) {
array_push($interval_array, date('d-H', strtotime($interval['date'])));
}
$newdata = (array_count_values($interval_array));
# which results as #
Array(
[17-20] => 1
[17-21] => 1
[17-23] => 2
[18-02] => 1
)