Bonjour
Voici mon souci, j'ai 3 tables (voir ci-dessous). La table T_relation est alimentée via un formulaire avec les infos contenues dans les tables T_personne et T_Projet
Je voudrai pouvoir afficher mes infos regroupées par titre de projet (explications ci-dessous)
T_personne
+-------------+--------+-----------+
| id_personne | prenom | nom |
+-------------+------------+-------+
| 3 | paul | ochon |
| 4 | jean | transcène |
| 5 | alain | térieur |
+-------------+--------+-----------+
T_projet
+-----------+----------+
| id_projet | titre |
+-----------+----------+
| 2 | projet1 |
| 3 | projet2 |
| 7 | projet3 |
+-----------+----------+
T_relation
+-------------+-------------+-----------+
| id_relation | id_personne | id_projet |
+-------------+-------------+-----------+
| 1 | 5 | 7 |
| 2 | 3 | 7 |
| 3 | 4 | 7 |
| 4 | 5 | 3 |
| 5 | 3 | 3 |
| 6 | 4 | 3 |
| 7 | 5 | 2 |
+-------------+-------------+-----------+
-------------------------------------------------------------------------------------------------------------------------------------------------------
La table relation, est alimentée via un formulaire (l'utilisateur à la possibilité de choisir plusieurs personnes):
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
| <form name="formContact" action="insert-relation-media.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="selectProjet">Projet</label>
<select name="selectProjet" id="selectProjet" class="form-control">
<?php
while ($lineProjet = mysql_fetch_array($resultProjet, MYSQL_ASSOC)) {
?>
<option value="<?php echo $lineProjet['id_projet'];?>"><?php echo $lineProjet['titre'];?> </option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label for="selectPersonne">Personne</label>
<select name="selectPersonne[]" multiple="multiple" size="10" class="form-control" id="selectPersonne">
<?php
while ($linePersonne = mysql_fetch_array($resultPersonne, MYSQL_ASSOC)) {
?>
<option value="<?php echo $linePersonne['id_personne'];?>"> <?php echo $linePersonne['nom'];?> <?php echo $linePersonne['prenom'];?> </option>
<?php
}
?>
</select>
</div>
<button type="submit" name="sub" class="btn btn-success">Envoyer</button> <input name="" type="reset" class="btn btn-danger">
</form> |
-------------------------------------------------------------------------------------------------------------------------------------------------------
Requête d'insertion dans la table relation (comme l'utilisateur a la possibilité de sélectionner plusieurs personnes pour un projet, cette requête me permet d'insérer une ligne par personne):
1 2 3 4 5 6 7 8 9
| // Récup données form
$projet = $_POST['selectProjet'];
$personne = $_POST['selectPersonne'];
// Insertion DB
foreach($personne as $i => $personne_id){
$personneGroups = mysql_query("INSERT INTO T_relation SET `id_relation`='', `id_personne`='{$personne_id}', `id_projet`='{$projet}'");
} |
-------------------------------------------------------------------------------------------------------------------------------------------------------
Jusqu'ici tout fonctionne parfaitement je n'ai aucun problème.
A présent, je voudrai pouvoir affichier mes infos regroupées par titre de projet comme ceci:
Nom du projet : PROJET 3
Personnes participantes : paul ochon | jean transcène | alain térieur
Nom du projet : PROJET 2
Personnes participantes : paul ochon | jean transcène | alain térieur
Nom du projet : PROJET 1
Personnes participantes : paul ochon
-------------------------------------------------------------------------------------------------------------------------------------------------------
J'ai essayé la requête suivante:
"
1 2 3 4 5 6 7 8 9 10 11
| SELECT T_relation.id_relation, T_relation.id_personne, T_relation.id_projet,
T_projet.titre
T_personne.nom, T_personne.prenom
FROM T_relation, T_projet, T_personne
WHERE T_relation.id_personne = T_personne.id_personne AND T_relation.id_projet = T_projet.id_projet
GROUP BY T_projet.titre
ORDER BY planmedia.id_planmedia |
";
-------------------------------------------------------------------------------------------------------------------------------------------------------
Mais le résultat d'affichage n'est pas concluant, il ne m'affiche qu'une personne, même si plusieurs participent au projet:
Nom du projet : PROJET 3
Personnes participantes : paul ochon
Nom du projet : PROJET 2
Personnes participantes : paul ochon
Nom du projet : PROJET 1
Personnes participantes : paul ochon
-------------------------------------------------------------------------------------------------------------------------------------------------------
Si j'enlève le GROUP BY il m'affiche ceci (ce qui est juste mais pas très élégant):
Nom du projet : PROJET 3
Personnes participantes : paul ochon
Nom du projet : PROJET 3
Personnes participantes : jean transcène
Nom du projet : PROJET 3
Personnes participantes : alain térieur
Nom du projet : PROJET 2
Personnes participantes : paul ochon
Nom du projet : PROJET 2
Personnes participantes : jean transcène
Nom du projet : PROJET 2
Personnes participantes : alain térieur
Nom du projet : PROJET 1
Personnes participantes : paul ochon
-------------------------------------------------------------------------------------------------------------------------------------------------------
Je sèche un peu et je ne vois pas comment arriver au résultat que je souhaite
Merci pour votre aide
Partager