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
| <div class="menug">
<?php
//Lecture d'une base de données pour créer un menu
try {
$options[PDO::ATTR_ERRMODE]=PDO::ERRMODE_EXCEPTION;
$db= new PDO('mysql:host=localhost;dbname=tests','root','',$options);
echo '<p>connexion à la base de données</p>';
}
catch (Exeption $e) {
die('erreur : '.$e->getMessage());
}
$parent = 0;
while($req = $db->query("SELECT * FROM menug WHERE ID_PARENT='$parent'")) {
;//Sélection du parent
$data = $req->fetch();
echo '<strong>idparent -'.$parent.'</strong><br />';
if(!$data) break;
$nbfille=$data['nbenfants'];
echo '<strong>nbenfant -'.$nbfille.'</strong><br />';
$enfant = $data['id_enfants'];
echo 'idenfant -'.$enfant.'<br/>';
if($enfant==0) {echo '<ul class="menug">'.$data['Titre'];}
if($nbfille !=0) {
if($enfant != 0) { echo '<li><a href="'.$data['Fichier'].'">'.$data['Titre'].'</a></li>';} //vérification s'il y a un enfant
}else{
echo '</ul>';
$parent++;}// Incrémentation et sélection du prochain parent
};
$req->closeCursor(); |
Partager