I want to be able to go through a sql query where I group the emails sent during certain years, the sent ones, the returned ones, etc ... For respective specific years for example for 2014, 2015, 2016, 2017, 2018. For this I designed the following query:
<?php
$totalCampo1 = 0;
$totalCampo2 = 0;
$totalCampo3 = 0;
$totalCampo4 = 0;
$totalCampo5 = 0;
$totalCampo6 = 0;
$totalCampo7 = 0;
$query = "SELECT SUM(campo1) AS totalcampo1, SUM(campo2) as totalcampo2, SUM(campo3) AS campo3, SUM(campo4) AS campo4, SUM(campo5) AS campo5, SUM(campo6) AS campo6, SUM(campo7) AS campo7, extract(year from fecha) as year1,
(extract(month from fecha)) as month1
FROM tabla WHERE id_admin = $variableiniciodesesion AND status = '3' AND extract(year from fechaenvio) BETWEEN 2014 AND 2018 GROUP BY year1, month1 order by year1, month1 asc";
$db->query($query);
$db->next_record();
$totalCampo1 = $db->f("Campo1");
$totalCampo2 = $db->f("Campo2");
$totalCampo3 = $db->f("Campo3");
$totalCampo4 = $db->f("Campo4");
$totalCampo5 = $db->f("Campo5");
$totalCampo6 = $db->f("Campo6");
$totalCampo7 = $db->f("Campo7");
?>
As you can see, start certain variables in 0, I make a query with summation and work in a $ db class that I established in my function files. In this way I can show without any problem the first record that brings the query, but I want a for or any other function that allows me to go through all the records that the query brings me and to show them in the fields of google and chart and graph me certain records, and to be honest I have no idea how to do it working in this way.
The code below only shows how the Google charts code runs with static data and I want to replace that static data with an array extracted from my database. Any help that allows me to solve this problem is good.
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['Año', 'Campo1', 'Campo2', 'Campo3', 'Campo4', 'Campo5', 'Campo6'],
['2004/05', 165, 938, 522, 998, 450, 614.6],
['2005/06', 135, 1120, 599, 1268, 288, 682],
['2006/07', 157, 1167, 587, 807, 397, 623],
['2007/08', 139, 1110, 615, 968, 215, 609.4],
['2008/09', 136, 691, 629, 1026, 366, 569.6]
]);
var options = {
title : 'Comportamiento total de las campañas',
vAxis: {title: 'Datos'},
hAxis: {title: 'Tiempo'},
seriesType: 'bars',
series: {5: {type: 'line'}}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 800px; height: 250px;"></div>
</body>