php - MySQL to display number of entries per hour in a table -
new link - results off 1i need echo in table number of entries per hour given date, if 0. seems happening in weird way... can see, hours column not playing ball should 0:00-1 .... 22.00-23.00 etc. total number of result expected 19 correct when sum results together. got point don't know happening in script , no idea start fixing formatting issues. appreciated.current result in html page
// list of times per hour reader $sqltimea = "select concat(hour, ':00-', hour+1, ':00') hours, count(r.readerid) tapcount ( select '0' hour union select '1' union select '2' union select '3' union select '4' union select '5' union select '6' union select '7' union select '8' union select '9' union select '10' union select '11' union select '12' union select '13' union select '14' union select '15' union select '16' union select '17' union select '18' union select '19' union select '20' union select '21' union select '22' union select '23' ) h left join taps t on hour(t.`time`) = hour , date(t.time) = '2016-01-15' left join readers r on r.readerid = t.readerid , r.type = 'a' group hour order hour"; $qtimea = mysql_query($sqltimea); // challenge! put in table! $hours = array("0:00-1:00", "1:00-2:00", "2:00-3:00", "3:00-4:00", "4:00-5:00", "5:00-6:00", "6:00-7:00", "7:00-8:00", "8:00-9:00", "9:00-10:00", "11:00-12:00", "12:00-13:00", "13:00-14:00", "14:00-15:00", "15:00-16:00", "16:00-17:00", "17:00-18:00", "18:00-19:00", "19:00-20:00", "20:00-21:00", "21:00-22:00", "22:00-23:00", "23:00-24:00"); for($i = 0; $i <= 23; $i++) { while($timea = mysql_fetch_assoc($qtimea)) { $tapsa = $timea['tapcount']; echo "<tr><td>" . $hours[$i] . "</td><td>" . $tapsa . "</td></tr>"; } } ?>
im not expert on php, i
variable doesnt incremented inside while
add $hours[$i++]
or label $timea['hours']
and dont need for
initialize i = 0
while($timea = mysql_fetch_assoc($qtimea)) { $tapsa = $timea['tapcount']; $hour_label = $timea['hours']; echo "<tr><td>" . $hour_label . "</td><td>" . $tapsa . "</td></tr>"; }
Comments
Post a Comment