1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <?php
$db = mysql_connect('localhost', 'XXX', 'XXX');
mysql_select_db('XXX',$db);
$sql = mysql_query("SELECT * FROM news");
$tResult = mysql_fetch_array($sql, MYSQL_BOTH); // contient toutes les données récupérees par ta requete SQL, par exemple avec un mysql_fetch_array();
// on va stocker tout dans un grand tableau associatif : $array[annee][mois][jour] = contenu
$tEvenements = array();
foreach($tResult as $row) {
$year = $row['annee'];
$month = $row['mois'];
$day = $row['jour'];
$text = $row['contenu'];
// création des sous tableaux
if(!isset($tEvenements[$year])) $tEvenements[$year] = array();
if(!isset($tEvenements[$year][$month])) $tEvenements[$year][$month] = array();
// ajout des données pour le jour. On pourrait aussi faire un sous tableau
if(isset($tEvenements[$year][$month][$day])) {
$tEvenements[$year][$month][$day] .= $text;
} else {
$tEvenements[$year][$month][$day] = $text;
}
}
// résultat:
print_r($tEvenements);
?>
|