Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $sql = mysql_query("SELECT time_hit FROM hits WHERE time_hit >= DATE_SUB(NOW(), INTERVAL 24 HOUR) ORDER BY time_hit DESC;")
- or die(mysql_error());
- // Remove an hour off current time for array and the loop that will put the data into the array
- $array_hour = $current_hour - 1;
- // Add a 0 if the timer is under 10. just so this is compatable with the SQL data
- if ($array_hour < 10) {
- $array_hour = 0 . $array_hour;
- }
- // initialise the array so we can set up the indexes and data in the next couple of loops
- $hit_data = array();
- // Work back the clock 24 hours and create the array indexes
- for ($i = 0; $i < 24; $i++) {
- $new_hour = $current_hour - 1;
- if ($new_hour < 1) {
- $new_hour = 24;
- $hit_data[$new_hour] = "";
- }
- else {
- $hit_data[$new_hour] = "";
- }
- $current_hour = $new_hour;
- }
- $incre = 1;
- while ($row = mysql_fetch_array($sql)) {
- if (substr($row['time_hit'], 11, 2) == $current_hour) {
- unset($row['time_hit']);
- continue;
- }
- // Make sure we don't go into negitives
- if ($array_hour < 1) {
- $array_hour = 24;
- }
- if ($current_hour < 1) {
- $current_hour = 24;
- }
- $hour_hit_count = 0;
- $loop_count = 0;
- foreach ($row as $value) {
- if (substr($value, 11, 2) == $array_hour) {
- $hour_hit_count++;
- }
- if ($loop_count > 100) {
- echo "<br />Loop Breaked!! - Value = " . substr($value, 11, 2) . " <br />";
- break;
- }
- else {
- $loop_count++;
- }
- }
- echo "<br /> hit count:" . $hour_hit_count . " array_hour = " . $array_hour . "<br />";
- // Add the count to the array
- if ($hour_hit_count > 0) {
- $hit_data[$array_hour] = $hour_hit_count;
- }
- else {
- $hit_data[$array_hour] = 0;
- }
- echo "(" . $incre . ") " . $row['time_hit'] . "<br />";
- $incre++;
- $array_hour --;
- $current_hour --;
- }
- // Loop through the rest of the array and replace null with 0s
- foreach ($hit_data as $index => $value) {
- if ($value == "") {
- $value = 0;
- }
- }
Add Comment
Please, Sign In to add comment