I have the following query inside a javascript that generates a graphic:
<script>
$(".sparkline_one").sparkline([<?php
$sql="select
count(id) as total,
DAY(dia_criacao) AS DAY,
MONTH(dia_criacao) AS MONTH,
YEAR(dia_criacao) AS YEAR
from chamados where dia_criacao BETWEEN DATE_SUB(NOW(), INTERVAL 2 WEEK) AND NOW() AND id_empresa='".$_SESSION['clientelogado']['id_empresa']."' GROUP BY YEAR(dia_criacao), MONTH(dia_criacao), DAY(dia_criacao) order by dia_criacao asc";
$query=mysqli_query($con,$sql);
$n=0;
while($result=mysqli_fetch_array($query,MYSQL_ASSOC)){
$chamados[]=$result['total'];
$dias[]="$n: '$result[DAY]/$result[MONTH]/$result[YEAR]'";
$n++;
}
$chamados=implode(",", $chamados);
echo $chamados;
?>], {
type: 'bar',
height: '125',
barWidth: 13,
tooltipFormat: 'Dia {{offset:offset}}<br>{{value}} chamado(s)',
tooltipValueLookups: {
'offset': {
<?php
$dias=implode(",", $dias);
echo $dias;
?>
}
},
colorMap: {
'7': '#a1a1a1'
},
barSpacing: 2,
barColor: '#26B99A'
});
</script>
It works fine but has only one problem: if there is a day that there were no open calls it does not display the day because there are no results in my db. I wonder if it is possible for mysql to return the days it has not called in the query order and with value 0? or if there is no way to do it? (am I going to have to loop around to see each separate day?)