Problème de boucle while sur base de données
Bonjour à tous. J'ai un petit problème de boucle. Je dois faire un planning de projet. J'ai créé 2 tables, une pour les projets et une pour les taches associées à chaque projet. Le but est d'afficher dans un tableau tous les projets stockés dans ma base de donnée mais que chacun soit suivi des taches qui lui sont attachées. en gros :
-Projet 1
-tache 1.1
-tache 1.2
-Projet 2
-tache 2.1
-Projet 3
-tache 3.1
-tache 3.2
-tache 3.3
Mais je n'arrive pas à afficher cela, seule la dernière tache que j'ai inséré dans ma base s'affiche. Cela donne donc:
-Projet 1
-Projet 2
-Projet 3
-tache 3.3
J'ai du faire une erreur dans les boucles mais j'ai beau chercher je ne vois pas. Voilà le code:
Code:
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| <table border="1" cellpadding="0" cellspacing="0">
<tr>
<th>  Projet   </th>
<th>  Commentaires   </th>
<th>  Responsable   </th>
<th>  Date début   </th>
<th>  Date fin   </th>
</tr>
<? include("connect_bdd_adn.php");
// Creation et envoi de la requete
$query = "SELECT Nom,id,Commentaires,res1,Date_debut,Date_fin FROM Projets";
$tache = "SELECT titre,id_projet,commentaires,res1,Date_debut,Date_fin FROM `Projets_definition`";
$result = mysql_query($query);
$result_tache = mysql_query($tache);
$tili="salut";
// Recuperation des resultats
while($roll = mysql_fetch_row($result_tache)){
//$query = mysql_query("SELECT a.Nom,a.id,a.Commentaires,a.res1,a.res2,a.res3,a.Date_debut,a.Date_fin,b.id_projet FROM Projets a,Projets_definition b WHERE a.id=b.id_projet");
//while($data = mysql_fetch_array($query)) {
echo "$id";
$titre = $roll[0];
$id_projet = $roll[1];
$Commentaires_tache = $roll[2];
$res1_tache = $roll[3];
$Date_debut_tache = $roll[4];
$Date_fin_tache = $roll[5];
while($row = mysql_fetch_row($result)){
$Nom = $row[0];
$id = $row[1];
$Commentaires = $row[2];
$res1 = $row[3];
$Date_début = $row[4];
$Date_fin = $row[5];
echo "<tr onMouseover=this.bgColor='yellow' onMouseout=this.bgColor='#FFFFFF'>\n
<td align=center><b>$Nom</b></td>\n
<td align=center>$Commentaires</td>\n
<td align=center>$res1</td>\n
<td align=center>$Date_début</td>\n
<td align=center>$Date_fin</td>\n
</tr>\n";
if($row[1] == $roll[1]){
echo "<tr onMouseover=this.bgColor='red' onMouseout=this.bgColor='#FFFFFF'>\n
<td align=center><b>$titre</b></td>\n
<td align=center>$Commentaires_tache</td>\n
<td align=center>$res1_tache</td>\n
<td align=center>$Date_debut_tache</td>\n
<td align=center>$Date_fin_tache</td>\n
</tr>\n";
}}}
// Deconnexion de la base de donnees
mysql_close();
?>
</tr>
</table> |
Merci par avance à qui pourra me filer un coup de main.