1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| $listeMois = ['janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juill.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'];
$data = [];
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
if (!isset($data[$row['ville']])) {
// init du tableau pour la ville
$data[$row['ville']] = array_fill_keys($listeMois, '');
}
$data[$row['ville']][$row['mois']] = $row['temperature'];
}
foreach ($data as $ville => $line) {
echo '<tr>';
echo '<th>'.$ville.'</th>';
foreach($line as $col) {
echo '<td>'.$col.'</td>';
}
echo '<tr>';
} |