Guest User

Untitled

a guest
Jul 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. $sql = mysql_query("SELECT time_hit FROM hits WHERE time_hit >= DATE_SUB(NOW(), INTERVAL 24 HOUR) ORDER BY time_hit DESC;")
  2. or die(mysql_error());
  3.  
  4. // Remove an hour off current time for array and the loop that will put the data into the array
  5. $array_hour = $current_hour - 1;
  6.  
  7. // Add a 0 if the timer is under 10. just so this is compatable with the SQL data
  8. if ($array_hour < 10) {
  9. $array_hour = 0 . $array_hour;
  10. }
  11.  
  12. // initialise the array so we can set up the indexes and data in the next couple of loops
  13. $hit_data = array();
  14.  
  15. // Work back the clock 24 hours and create the array indexes
  16. for ($i = 0; $i < 24; $i++) {
  17. $new_hour = $current_hour - 1;
  18.  
  19. if ($new_hour < 1) {
  20. $new_hour = 24;
  21. $hit_data[$new_hour] = "";
  22. }
  23. else {
  24. $hit_data[$new_hour] = "";
  25. }
  26.  
  27. $current_hour = $new_hour;
  28. }
  29.  
  30. $incre = 1;
  31. while ($row = mysql_fetch_array($sql)) {
  32. if (substr($row['time_hit'], 11, 2) == $current_hour) {
  33. unset($row['time_hit']);
  34. continue;
  35. }
  36.  
  37. // Make sure we don't go into negitives
  38. if ($array_hour < 1) {
  39. $array_hour = 24;
  40. }
  41.  
  42. if ($current_hour < 1) {
  43. $current_hour = 24;
  44. }
  45.  
  46. $hour_hit_count = 0;
  47. $loop_count = 0;
  48. foreach ($row as $value) {
  49. if (substr($value, 11, 2) == $array_hour) {
  50. $hour_hit_count++;
  51. }
  52.  
  53. if ($loop_count > 100) {
  54. echo "<br />Loop Breaked!! - Value = " . substr($value, 11, 2) . " <br />";
  55. break;
  56. }
  57. else {
  58. $loop_count++;
  59. }
  60. }
  61.  
  62. echo "<br /> hit count:" . $hour_hit_count . " array_hour = " . $array_hour . "<br />";
  63.  
  64. // Add the count to the array
  65. if ($hour_hit_count > 0) {
  66. $hit_data[$array_hour] = $hour_hit_count;
  67. }
  68. else {
  69. $hit_data[$array_hour] = 0;
  70. }
  71.  
  72. echo "(" . $incre . ") " . $row['time_hit'] . "<br />";
  73.  
  74. $incre++;
  75. $array_hour --;
  76. $current_hour --;
  77. }
  78.  
  79. // Loop through the rest of the array and replace null with 0s
  80. foreach ($hit_data as $index => $value) {
  81. if ($value == "") {
  82. $value = 0;
  83. }
  84. }
Add Comment
Please, Sign In to add comment