Boucles et mysqli_fecth_array
bonjour a toutes et a tous!
je veux afficher le nombre existant de materiel (disponible et indisponible) de chaque catégorie tt en affichant un tableau pr afficher a la fois la categorie, Nombre, nombre disponible et nombre indisponible
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
|
<?php
if (isset($_POST['choixCat']))
{
$catchoisi=$_POST['choixCat'];
$catchoisi=$db->real_escape_string($catchoisi);
$select = "SELECT designation,type,dispo,description FROM materiel WHERE `designation`='$catchoisi'";
$result = $db->query($select)or die ('There was an error [' . $db->error . ']');
$total = mysqli_num_rows($result);
echo 'yes';
echo '<center><h2>SITUATION GLOBALE DU :';
echo $catchoisi;
echo '</h2></center>';
if($total) {
// debut du tableau
echo ' <center><table bgcolor="#FFFFFF" width="1050" border="0" align="center" cellpadding="0" cellspacing="0">'."\n";
echo '<tr style="height:1 cm;">';
echo '<td bgcolor="#669999"><b><u>Désignation</u></b></td>';
echo '<td bgcolor="#669999" style="width:6 cm;"><b><u>Caractéristiques techniques</u></b></td>' ;
echo '<td bgcolor="#669999"><b><u>Dotation</u></b></td>';
echo '<td bgcolor="#669999"><b><u>Disponible</u></b></td>';
echo '<td bgcolor="#669999"><b><u>Indisponible</u></b></td>';
echo '</tr>'."\n";
$dispo=0;
$indispo=0;
/*while($row = mysqli_fetch_array($result)) {$i++;}*/
while($row= mysqli_fetch_array($result)) {
$type=$row["type"];
echo '<tr>';
echo '<td bgcolor="#CCCCCC">'.$row["designation"].''; echo ' '.$row["type"].'</td>';
while($row = mysqli_fetch_array($result))
{
if($row["type"]==$type)
{
if($row["dispo"]==0)
$indispo++;
else $dispo++;
}
}
echo '<td bgcolor="#CCCCCC">';echo $dispo+$indispo;echo'</td>';
echo '<td bgcolor="#CCCCCC">';echo $dispo;echo'</td>';
echo '<td bgcolor="#CCCCCC">';echo $indispo;echo'</td>';
echo '</tr>'."\n";
$dispo=0;
$indispo=0;
}
echo '</table></center>'."\n";
// fin du tableau.
}
}
?> |
mon probleme c est au niveau de la boucle,
je veux quand il recoit une ligne il lit le type puis parcours le tableau s il trouve mm type incremente la dotation(Nombre) et si $dispo==true incremente $dispo
merci d'avance!