Hello,
I'm building a statistics system.
The result is an Array with "time" and "views".
I need to increment this data 24 hours a day for the chart to be complete.
$sql = "SELECT HOUR(data) as hora, COUNT(id) as views "
. "FROM trafego "
. "WHERE data >= '{$periodo}' "
. "GROUP BY hora ";
$query = $this->db->query($sql);
$result = $query->fetchALL(PDO::FETCH_OBJ);
THE RESULT THAT I HAVE IS
0 =>
object(stdClass)[4]
public 'hora' => string '1' (length=1)
public 'views' => string '3' (length=1)
1 =>
object(stdClass)[5]
public 'hora' => string '4' (length=1)
public 'views' => string '3' (length=1)
2 =>
object(stdClass)[6]
public 'hora' => string '8' (length=1)
public 'views' => string '5' (length=1)
3 =>
object(stdClass)[7]
public 'hora' => string '10' (length=2)
public 'views' => string '4' (length=1)
4 =>
object(stdClass)[8]
public 'hora' => string '11' (length=2)
public 'views' => string '7' (length=1)
5 =>
object(stdClass)[9]
public 'hora' => string '21' (length=2)
public 'views' => string '3' (length=1)
6 =>
object(stdClass)[10]
public 'hora' => string '22' (length=2)
public 'views' => string '3' (length=1)
How to increment this array with the hours and add 0 views?
Example, I have schedules 1, 4, 8, 10, 11, 21, 22
I need to add missing times and these should have 0 views
hora views
1 -> 3
2 -> 0 (faltante, por isso deve ser 0)
3 -> 0 (faltante, por isso deve ser 0)
4 -> 3
So it goes on for up to 24 hours. (0 ~ 23)