Recuperer le resultat d'une requete....
trik59
Messages postés
244
Date d'inscription
Statut
Membre
Dernière intervention
-
yannick -
yannick -
Bojour,
je work en php et mysql.... aprés avoir creer un tableau dans lesquel je souhaite recuper le resultat de ma requete, ....voila il se trouve que je ne c'est pas comment recuperer mon résultat et l'affecter ds mon tableau??
voici ma requete:
if ($err == 0){
$requete = "SELECT division.id_div, division.nom_div, type_mat.id_sorte_mat, materiel.statut, count( * ) nbr_ucs
FROM materiel, type_mat, division WHERE type_mat.id_sorte_mat = $smat
AND materiel.statut = \"A\"
AND materiel.id_type_mat = type_mat.id_type_mat
AND materiel.id_div = division.id_div AND materiel.date_livraison <=\"$ddate\"
GROUP BY division.id_div;";
//recupere le resultat de requete
$resultat = requeteSQL($requete);
//vérification qu'il y a au moins une ligne de résultat
if(mysql_num_rows($resultat)) $i = 0;
{
//récupération du résultat de la requête ligne par ligne
while($tab = mysql_fetch_row($resultat))
Ici je ne comprend pas pourkoi au lieu qu'il d'afficher le resultat de ma requete, il affiche plusieurs fois en boucle les champs de mon tableau(id_div, nom de la div...) sauriez vous pourquoi ?
}
//recuepre ds tableau
?>
<div align='center'>
<center><table border='0' width='350' cellspacing='0' cellpadding='0' height='0' style='margin-left: 30px'>
<tr align='center'>
</table>
</div>
<div align='center'>
<center><table border='0' width='380' cellspacing='0' cellpadding='0' height='5' style='margin-left: 20px'>
<tr align='left'>
</tr>
</table>
<table border='1' width='780' bordercolordark='#808080' cellspacing='1' bordercolor='#C0C0C0' bordercolorlight='#C0C0C0' height='30' bgcolor='#FFFFFFF'>
<tr>
<th width='10%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> N° Division </font></strong></th>
<th width='20%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Nom Dividion </font></strong></th>
<th width='15%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Sorte materiel </font></strong></th>
<th width='10%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Statut </font></strong></th>
<th width='25%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Nombre de PC </font></strong></th>
</tr>
<tr>
<td style='border: 1 outset #000099' width='10%' align='center' checked='false' BGCOLOR='#CCCCCCCC'><font face='Arial' size='2' align ='center'><?php echo $row['tie_tiers']; ?></font></td>
<td style='border: 1 outset #000099' width='20%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['tie_nommar']; ?></font></td>
<td style='border: 1 outset #000099' width='15%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['tie_prenom']; ?></font></td>
<td style='border: 1 outset #000099' width='30%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['com_libcomm']; ?></font></td>
<td style='border: 1 outset #000099' width='25%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['act_mail']; ?></font></td>
</tr>
<?php
voila j'spere que j'ai reussi a vous faire comprendre mon ti probleme, merci beaucoup
cordialement!
je work en php et mysql.... aprés avoir creer un tableau dans lesquel je souhaite recuper le resultat de ma requete, ....voila il se trouve que je ne c'est pas comment recuperer mon résultat et l'affecter ds mon tableau??
voici ma requete:
if ($err == 0){
$requete = "SELECT division.id_div, division.nom_div, type_mat.id_sorte_mat, materiel.statut, count( * ) nbr_ucs
FROM materiel, type_mat, division WHERE type_mat.id_sorte_mat = $smat
AND materiel.statut = \"A\"
AND materiel.id_type_mat = type_mat.id_type_mat
AND materiel.id_div = division.id_div AND materiel.date_livraison <=\"$ddate\"
GROUP BY division.id_div;";
//recupere le resultat de requete
$resultat = requeteSQL($requete);
//vérification qu'il y a au moins une ligne de résultat
if(mysql_num_rows($resultat)) $i = 0;
{
//récupération du résultat de la requête ligne par ligne
while($tab = mysql_fetch_row($resultat))
Ici je ne comprend pas pourkoi au lieu qu'il d'afficher le resultat de ma requete, il affiche plusieurs fois en boucle les champs de mon tableau(id_div, nom de la div...) sauriez vous pourquoi ?
}
//recuepre ds tableau
?>
<div align='center'>
<center><table border='0' width='350' cellspacing='0' cellpadding='0' height='0' style='margin-left: 30px'>
<tr align='center'>
</table>
</div>
<div align='center'>
<center><table border='0' width='380' cellspacing='0' cellpadding='0' height='5' style='margin-left: 20px'>
<tr align='left'>
</tr>
</table>
<table border='1' width='780' bordercolordark='#808080' cellspacing='1' bordercolor='#C0C0C0' bordercolorlight='#C0C0C0' height='30' bgcolor='#FFFFFFF'>
<tr>
<th width='10%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> N° Division </font></strong></th>
<th width='20%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Nom Dividion </font></strong></th>
<th width='15%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Sorte materiel </font></strong></th>
<th width='10%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Statut </font></strong></th>
<th width='25%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Nombre de PC </font></strong></th>
</tr>
<tr>
<td style='border: 1 outset #000099' width='10%' align='center' checked='false' BGCOLOR='#CCCCCCCC'><font face='Arial' size='2' align ='center'><?php echo $row['tie_tiers']; ?></font></td>
<td style='border: 1 outset #000099' width='20%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['tie_nommar']; ?></font></td>
<td style='border: 1 outset #000099' width='15%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['tie_prenom']; ?></font></td>
<td style='border: 1 outset #000099' width='30%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['com_libcomm']; ?></font></td>
<td style='border: 1 outset #000099' width='25%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['act_mail']; ?></font></td>
</tr>
<?php
voila j'spere que j'ai reussi a vous faire comprendre mon ti probleme, merci beaucoup
cordialement!
A voir également:
- Recuperer le resultat d'une requete....
- Recuperer message whatsapp supprimé - Guide
- Resultat foot - Télécharger - Vie quotidienne
- Comment recuperer une video sur youtube - Guide
- Recuperer le son d'une video - Guide
- Récupérer mon compte facebook désactivé - Guide
1 réponse
Je pense avoir compris ton problème
Vérifie d'abord le bon positionnement de tes accolades.
Ensuite à la place de sa : while($tab = mysql_fetch_row($resultat))
Met ça : while($row = mysql_fetch_assoc($resultat))
Je pense pour ma part que tu devrais faire :
<div align='center'>
<center><table border='0' width='350' cellspacing='0' cellpadding='0' height='0' style='margin-left: 30px'>
<tr align='center'>
</table>
</div>
<div align='center'>
<center><table border='0' width='380' cellspacing='0' cellpadding='0' height='5' style='margin-left: 20px'>
<tr align='left'>
</tr>
</table>
<table border='1' width='780' bordercolordark='#808080' cellspacing='1' bordercolor='#C0C0C0' bordercolorlight='#C0C0C0' height='30' bgcolor='#FFFFFFF'>
<tr>
<th width='10%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> N° Division </font></strong></th>
<th width='20%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Nom Dividion </font></strong></th>
<th width='15%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Sorte materiel </font></strong></th>
<th width='10%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Statut </font></strong></th>
<th width='25%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Nombre de PC </font></strong></th>
</tr>
<?php
do{
?>
<tr>
<td style='border: 1 outset #000099' width='10%' align='center' checked='false' BGCOLOR='#CCCCCCCC'><font face='Arial' size='2' align ='center'><?php echo $row['tie_tiers']; ?></font></td>
<td style='border: 1 outset #000099' width='20%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['tie_nommar']; ?></font></td>
<td style='border: 1 outset #000099' width='15%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['tie_prenom']; ?></font></td>
<td style='border: 1 outset #000099' width='30%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['com_libcomm']; ?></font></td>
<td style='border: 1 outset #000099' width='25%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['act_mail']; ?></font></td>
</tr>
<?php
}while($row = mysql_fetch_assoc($resultat));
?>
Vérifie d'abord le bon positionnement de tes accolades.
Ensuite à la place de sa : while($tab = mysql_fetch_row($resultat))
Met ça : while($row = mysql_fetch_assoc($resultat))
Je pense pour ma part que tu devrais faire :
<div align='center'>
<center><table border='0' width='350' cellspacing='0' cellpadding='0' height='0' style='margin-left: 30px'>
<tr align='center'>
</table>
</div>
<div align='center'>
<center><table border='0' width='380' cellspacing='0' cellpadding='0' height='5' style='margin-left: 20px'>
<tr align='left'>
</tr>
</table>
<table border='1' width='780' bordercolordark='#808080' cellspacing='1' bordercolor='#C0C0C0' bordercolorlight='#C0C0C0' height='30' bgcolor='#FFFFFFF'>
<tr>
<th width='10%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> N° Division </font></strong></th>
<th width='20%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Nom Dividion </font></strong></th>
<th width='15%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Sorte materiel </font></strong></th>
<th width='10%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Statut </font></strong></th>
<th width='25%' bgcolor='#9999CC'><strong><font face='Arial' size='2'> Nombre de PC </font></strong></th>
</tr>
<?php
do{
?>
<tr>
<td style='border: 1 outset #000099' width='10%' align='center' checked='false' BGCOLOR='#CCCCCCCC'><font face='Arial' size='2' align ='center'><?php echo $row['tie_tiers']; ?></font></td>
<td style='border: 1 outset #000099' width='20%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['tie_nommar']; ?></font></td>
<td style='border: 1 outset #000099' width='15%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['tie_prenom']; ?></font></td>
<td style='border: 1 outset #000099' width='30%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['com_libcomm']; ?></font></td>
<td style='border: 1 outset #000099' width='25%' align='center' checked='false' BGCOLOR='#FFFFCC'><font face='Arial' size='2'><?php echo $row['act_mail']; ?></font></td>
</tr>
<?php
}while($row = mysql_fetch_assoc($resultat));
?>