Pb avec tableau

Fermé
g21dijon - 6 mars 2008 à 11:04
Dalida Messages postés 6728 Date d'inscription mardi 14 mai 2002 Statut Contributeur Dernière intervention 11 janvier 2016 - 7 mars 2008 à 11:21
Bonjour à tous,

j'ai un petit problème avec du php sur un site intranet, ce problème est que je n'arrive pas à récupérer dans un tableau HTML que je construit avec un base de données (boucle while sur le jeu d'enregistrement) les valeurs de mes produits.
Enfin tout du moins il ne me récupère seulement le numéro du premier produit afficher dans le tableau...
Je vous joint la partie de mon code pr savoir qu'elle est ce problème..
Je vous remercie par avance en attendant des réponses qui résoluront mon pb.

if($typ!="")
{
$rp="select * from produit where produit.num_type='".$typ."' order by num_prod;";
$rsltp=mysql_query($rp,$con);
$ligp=mysql_fetch_array($rsltp);
echo '<TABLE border="1">';
echo '<tr>';
echo '<td>Code Produit</td>';
echo '<td>Designation</td>';
echo '<td>Quantité</td>';
echo '<td>Choisir</td>';
echo "</tr>";
if(mysql_num_rows($rsltp)!=0)
{
while($ligp!=FALSE)
{
$i=$i+1;
$np=utf8_decode($ligp['num_prod']);
$libp=utf8_decode($ligp['lib_prod']);
echo "<tr>";
echo "<td>".$np."</td>";
echo "<td>".$libp."</td>";
echo "<td><input type='text' name='qte'/></td>";
echo "<td><input type='submit' name='choix' value='Ajouter à la commande'/>";

$insl="insert into ligne_commande(num_lig, num_cde, qte_cde, num_prod) "
."values (".$derl.", ".$_SESSION['cde'].", ".$_POST['qte'].", ".$ligp['num_prod'].");";
$rsltlg=mysql_query($insl,$con);
echo "</tr>";
$ligp=mysql_fetch_array($rsltp);
}
}
echo "</TABLE>";

3 réponses

Dalida Messages postés 6728 Date d'inscription mardi 14 mai 2002 Statut Contributeur Dernière intervention 11 janvier 2016 920
6 mars 2008 à 12:46
salut,

il faut tester le résultat de 'mysql_fetch_array()' directement dans la condition du 'while()'
while( $ligp = mysql_fetch_array($rsltp) )
{
$i=$i+1;
$np=utf8_decode($ligp['num_prod']);
$libp=utf8_decode($ligp['lib_prod']);
echo "<tr>";
echo "<td>".$np."</td>";
echo "<td>".$libp."</td>";
echo "<td><input type='text' name='qte'/></td>";
echo "<td><input type='submit' name='choix' value='Ajouter à la commande'/>";

$insl="insert into ligne_commande(num_lig, num_cde, qte_cde, num_prod) "
."values (".$derl.", ".$_SESSION['cde'].", ".$_POST['qte'].", ".$ligp['num_prod'].");";
$rsltlg=mysql_query($insl,$con);
echo "</tr>";
} 

pense à utiliser le bouton "Conserver la mise en forme du texte sélectionné" pour mettre en forme ton code, merci !
0
merci Dalida pour cette info mais je dois décidemment pas etre très doué car cela ne fonctionne tjrs pas pourrai tu regarder encore une fois mon code stp. jte remercie beaucoup.



<?php
$rag="select num_ag, lib_ag from agence where num_ag='".$_SESSION['ag']."' order by num_ag;";
$rsltag=mysql_query($rag);
$ligag=mysql_fetch_array($rsltag);
echo "Vous êtes ".$_SESSION['log']." de l'agence du ".utf8_decode($ligag['lib_ag']).".";
echo "<div align='center'>";
echo "<h1>Nouvelle commande</h1>";
echo "<br><br>";
echo '<select name="listyp" size="1" onchange="submit()">';
$req="select * from type order by num_type;";
$rstyp=mysql_query($req,$con);
$ligt=mysql_fetch_array($rstyp);
if(mysql_num_rows($rstyp)!=0)
{
while($ligt!=FALSE)
{
$numt=utf8_decode($ligt['num_type']);
$libt=utf8_decode($ligt['lib_type']);
echo "<option value='$numt'";
if($numt==$typ)
{
echo " selected";
}
echo ">".$libt."</option>";
$ligt=mysql_fetch_array($rstyp);
}
}
echo "</select>";
echo "<br><br>";
$reql="select * from ligne_commande where num_cde=".$_SESSION['cde']." order by num_lig DESC;";
$rsltl=mysql_query($reql,$con);
$i=1;
$lgl=mysql_fetch_array($rsltl);
$derl=$lgl['num_lig']+1;
echo "<br><br>";
if($typ!="")
{
$rp="select * from produit where produit.num_type='".$typ."' order by num_prod;";
$rsltp=mysql_query($rp,$con);
echo '<TABLE border="1" >';
echo '<tr>';
echo '<td>Code Produit</td>';
echo '<td>Designation</td>';
echo '<td>Quantité</td>';
echo '<td>Choisir</td>';
echo "</tr>";
while(mysql_num_rows($rsltp)!=0)
{
while( $ligp = mysql_fetch_array($rsltp) )
{
$i=$i+1;
$np=utf8_decode($ligp['num_prod']);
$libp=utf8_decode($ligp['lib_prod']);
echo "<tr>";
echo "<td>".$np."</td>";
echo "<td>".$libp."</td>";
echo "<td><input type='text' name='qte'/></td>";
echo "<td><input type='submit' name='choix' value='Ajouter à la commande'/>";

$insl="insert into ligne_commande(num_lig, num_cde, qte_cde, num_prod) "
."values (".$derl.", ".$_SESSION['cde'].", ".$_POST['qte'].", ".$ligp['num_prod'].");";
$rsltlg=mysql_query($insl,$con);
echo "</tr>";
$ligp=mysql_fetch_array($rsltp);
}
}
}
echo "</TABLE>";

echo "</div>";
echo "choix".$i;
?>
0
Dalida Messages postés 6728 Date d'inscription mardi 14 mai 2002 Statut Contributeur Dernière intervention 11 janvier 2016 920
7 mars 2008 à 00:28
mais il faut aussi modifier la première boucle !
<?php
	while( $ligt=mysql_fetch_array($rstyp) )
	{
		$numt=utf8_decode($ligt['num_type']);
		$libt=utf8_decode($ligt['lib_type']);
		echo "<option value='$numt'";
		if($numt==$typ)
		{
			echo " selected";
		}
		echo ">".$libt."</option>";
	} 
?>

et le bouton pour le code, c'est celui-là !
-;o)
0
merci c sympa pr les reponses que tu m'apportes mais malheureusement je crois que sa fai la meme chose enfin ce n'est pas grave merci tt de meme..
0
Dalida Messages postés 6728 Date d'inscription mardi 14 mai 2002 Statut Contributeur Dernière intervention 11 janvier 2016 920
7 mars 2008 à 11:21
salut,

mais que se passe-t-il ?

erreur ou pas erreur ?
0