1
Hello,
I’m putting together a statistical system.
The result is an Array with "time" and "views".
I need to increment this data with 24 hours a day so that the graph is 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 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 the schedules 1, 4, 8, 10 ,11, 21, 22
I need to add missing times and these must 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 follows up to 24 hours. (0 ~ 23)
I don’t understand what you want to increment in hours... You can give an example of the result you want?
– MagicHat