Nouveau WRInaute
Bonjour à tous,
Je tente d'organiser la production d'un json sous le format Mois/Poids en 2019/Poids en 2020
Mon code actuel tiens compte de l'année puisque mon array Table produit les données par ligne.
Quelqu'un peut il me filer une astuce pour solutionner mon problème ?
D'avance merci à tous !
Ci-dessous mon code :
Je tente d'organiser la production d'un json sous le format Mois/Poids en 2019/Poids en 2020
Mon code actuel tiens compte de l'année puisque mon array Table produit les données par ligne.
Quelqu'un peut il me filer une astuce pour solutionner mon problème ?
D'avance merci à tous !
Ci-dessous mon code :
Code:
<?php
$result = $cnx->prepare('SELECT tonnage_collecte, DATE_FORMAT(date_collecte_vgtx,"%M") AS mois_vgtx FROM tonnages_vegetaux WHERE YEAR(date_collecte_vgtx)=YEAR(CURRENT_DATE()) UNION SELECT tonnage_collecte AS TONNEN1, DATE_FORMAT(date_collecte_vgtx,"%M") AS mois_vgtx FROM tonnages_vegetaux WHERE YEAR(date_collecte_vgtx)=YEAR(CURRENT_DATE())-1');
$result->execute();
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'Periode', 'type' => 'string'),
array('label' => 'Tonnage en 2019', 'type' => 'number'),
array('label' => 'Tonnage en 2020', 'type' => 'number')
);
foreach($result as $r){
$temp = array();
$temp[] = array('v' => (string) $r['mois_vgtx']);
$temp[] = array('v' => (int) $r['tonnage_collecte']);
$temp[] = array('v' => (int) $r['TONNEN1']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
// convert data into JSON format
$jsonTable = json_encode($table);
//echo $jsonTable;
print_r($jsonTable);
?>