I'm doing a local project and i have a few problems that cant resolve, i search information in this phorum but couldnt fix this problem.
First: I do a SQL query, thats the result:
Cantidad anio
115.77 2015
301.35 2016
1603.81 2017
Now i want to do a graphic line canvas, where on data i will put the range of years (range is chosen by user). I Will draw on the PHP file, this is my file now where the error is:
Notice: Array to string conversion on line 42
I though do a auxiliar acumulative variable and put this var on the script, but didnt work. I dont know if there are another best way to do it, and i will be glad with help.
Regards and thanks for read!
PD: I fixed the line 42, sorry about that: $aux+= " {year: '$anio', value: $dinero}";
<?php
include dirname(__FILE__).'/../Database/dbcon.php';
header('Content-Type: text/html; charset=utf-8');
$inicio=$_REQUEST['inicio'];
$fin=$_REQUEST['final'];
$anio=0;
$dinero=0;
$sql="Select SUM(gastos.Cantidad) 'Cantidad', year(gastos.Fecha) 'anio'
from ciclo
inner join gastos on ciclo.Identificador=gastos.year_id
where ciclo.Ciclo BETWEEN $inicio and $fin GROUP by anio";
$resultado=$conn->query($sql) or die('fecha_fin');
$resul_field=$resultado->field_count;
$array_mes[]=array();
$array_cantidad[]=array();
$total[]=array();
$contador=0;
$c=0;
$aux=0;
while($fila = mysqli_fetch_assoc($resultado)){
foreach ($fila as $key => $value) {
$anio=$fila['anio'];
$Cantidad=$fila['Cantidad'];
}
$array_cantidad[$c]=$Cantidad;
$array_mes[$c]=$anio;
$c++;
}
$long=count($array_cantidad);
for ($i=0; $i < $long; $i++) {
$contador=$array_mes[$i];
if($contador<$fin){
$anio=$array_mes[$i];
$dinero=$array_cantidad[$i];
$aux+=" {year: '$anio', value: $dinero},";
}else{
$anio=$array_mes[$i];
$dinero=$array_cantidad[$i];
**$aux+= " {year: '$anio', value: $dinero}";**
}
}
echo "
<script>
new Morris.Line({
element: 'graph_line',
xkey: 'year',
ykeys: ['value'],
labels: ['Value'],
hideHover: 'auto',
lineColors: ['#26B99A', '#34495E', '#ACADAC', '#3498DB'],
data: [
$aux;
]
});
</script>";
?>