Merci à tous les intervenants, leur réponses m'ont bien aidé. Je me suis inspiré de la réponse de Igor206 et de Ryle pour construire le code suivant :
<?php
$db = mysql_connect("localhost","root", "") or die ('erreur de connexion');
mysql_select_db('***',$db);
$select = "SELECT L.ID_LIVRE, C.NOM_CATEGORIE
FROM LIVRE L
INNER JOIN CLASSIFIE3 A ON A.ID_LIVRE = L.ID_LIVRE
INNER JOIN CATEGORIE C ON A.ID_CATEGORIE = C.ID_CATEGORIE";
$resultat = mysql_query($select);
// on déclare notre tableau avant de l'utiliser (évite les "notice")
$livre_categorie = array();
while ($data = mysql_fetch_array($resultat)){ // on parcours les enregistrements de ta requête
// si le livre n'est pas encore déclaré dans le tableau, on déclare le sous tab
if ( !isSet($livre_categorie[$data['ID_LIVRE']]) )
$livre_categorie[$data['ID_LIVRE']] = array();
// On ajoute ensuite dans le tableau du livre la catégorie
$livre_categorie[$data['ID_LIVRE']][] = $data ['NOM_CATEGORIE'];
echo $data['ID_LIVRE'].' : '.$data['NOM_CATEGORIE'].'<br/>';
}
$select = "SELECT L.ID_LIVRE, CB.NOM_CONTRIBUTEUR, CB.PRENOM_CONTRIBUTEUR, F.NOM_FONCTION
FROM LIVRE L
INNER JOIN PARTICIPE P ON P.ID_LIVRE = L.ID_LIVRE
INNER JOIN CONTRIBUTEURS CB ON CB.ID_CONTRIBUTEUR = P.ID_CONTRIBUTEUR
INNER JOIN FONCTION F ON F.ID_FONCTION = P.ID_FONCTION";
$resultat = mysql_query($select);
// on déclare notre tableau avant de l'utiliser (évite les "notice")
$livre_contributeurs= array();
while ($data = mysql_fetch_array($resultat)){ // on parcours les enregistrements de ta requête
// si le livre n'est pas encore déclaré dans le tableau, on déclare le sous tab
if ( !isSet($livre_contributeurs[$data['ID_LIVRE']]) )
$livre_contributeurs[$data['ID_LIVRE']] = array();
// On ajoute ensuite dans le tableau du livre le nom du contributeur,prénom et fonction
$livre_contributeurs[$data['ID_LIVRE']][] = $data ['NOM_CONTRIBUTEUR'];
$livre_contributeurs[$data['ID_LIVRE']][] = $data ['PRENOM_CONTRIBUTEUR'];
$livre_contributeurs[$data['ID_LIVRE']][] = $data ['NOM_FONCTION'];
echo $data['ID_LIVRE'].' : '.$data['PRENOM_CONTRIBUTEUR'].' '.$data['NOM_CONTRIBUTEUR'].' : '.$data['NOM_FONCTION'].'<br/>';
}
?>
L'affichage obtenu est du style :
(...)
239 : Romans
254 : Romans
255 : Romans
255 : Recueils nouvelles
etc
Puis :
(...)
239 : Edith Ochs : traducteur
239 : Arthur Phillips : auteur
254 : Maxime Chattam : auteur
255 : Jacques Baudou : prefaceur
255 : René Réouven : auteur
etc
Comment faire pour obtenir cet affichage (par ex. pour le id_livre 255) :
255 : Romans; recueil de nouvelles
auteur : René Réouven
prefaceur : Jacques Baudou
Merci pour toute aide complémentaire.
Merci à tous les intervenants, leur réponses m'ont bien aidé. Je me suis inspiré de la réponse de Igor206 et de Ryle pour construire le code suivant :
[php]<?php
$db = mysql_connect("localhost","root", "") or die ('erreur de connexion');
mysql_select_db('***',$db);
$select = "SELECT L.ID_LIVRE, C.NOM_CATEGORIE
FROM LIVRE L
INNER JOIN CLASSIFIE3 A ON A.ID_LIVRE = L.ID_LIVRE
INNER JOIN CATEGORIE C ON A.ID_CATEGORIE = C.ID_CATEGORIE";
$resultat = mysql_query($select);
// on déclare notre tableau avant de l'utiliser (évite les "notice")
$livre_categorie = array();
while ($data = mysql_fetch_array($resultat)){ // on parcours les enregistrements de ta requête
// si le livre n'est pas encore déclaré dans le tableau, on déclare le sous tab
if ( !isSet($livre_categorie[$data['ID_LIVRE']]) )
$livre_categorie[$data['ID_LIVRE']] = array();
// On ajoute ensuite dans le tableau du livre la catégorie
$livre_categorie[$data['ID_LIVRE']][] = $data ['NOM_CATEGORIE'];
echo $data['ID_LIVRE'].' : '.$data['NOM_CATEGORIE'].'<br/>';
}
$select = "SELECT L.ID_LIVRE, CB.NOM_CONTRIBUTEUR, CB.PRENOM_CONTRIBUTEUR, F.NOM_FONCTION
FROM LIVRE L
INNER JOIN PARTICIPE P ON P.ID_LIVRE = L.ID_LIVRE
INNER JOIN CONTRIBUTEURS CB ON CB.ID_CONTRIBUTEUR = P.ID_CONTRIBUTEUR
INNER JOIN FONCTION F ON F.ID_FONCTION = P.ID_FONCTION";
$resultat = mysql_query($select);
// on déclare notre tableau avant de l'utiliser (évite les "notice")
$livre_contributeurs= array();
while ($data = mysql_fetch_array($resultat)){ // on parcours les enregistrements de ta requête
// si le livre n'est pas encore déclaré dans le tableau, on déclare le sous tab
if ( !isSet($livre_contributeurs[$data['ID_LIVRE']]) )
$livre_contributeurs[$data['ID_LIVRE']] = array();
// On ajoute ensuite dans le tableau du livre le nom du contributeur,prénom et fonction
$livre_contributeurs[$data['ID_LIVRE']][] = $data ['NOM_CONTRIBUTEUR'];
$livre_contributeurs[$data['ID_LIVRE']][] = $data ['PRENOM_CONTRIBUTEUR'];
$livre_contributeurs[$data['ID_LIVRE']][] = $data ['NOM_FONCTION'];
echo $data['ID_LIVRE'].' : '.$data['PRENOM_CONTRIBUTEUR'].' '.$data['NOM_CONTRIBUTEUR'].' : '.$data['NOM_FONCTION'].'<br/>';
}
?>[/php]
L'affichage obtenu est du style :
(...)
239 : Romans
254 : Romans
255 : Romans
255 : Recueils nouvelles
etc
Puis :
(...)
239 : Edith Ochs : traducteur
239 : Arthur Phillips : auteur
254 : Maxime Chattam : auteur
255 : Jacques Baudou : prefaceur
255 : René Réouven : auteur
etc
Comment faire pour obtenir cet affichage (par ex. pour le id_livre 255) :
255 : Romans; recueil de nouvelles
auteur : René Réouven
prefaceur : Jacques Baudou
Merci pour toute aide complémentaire.