Pb avec tableau
g21dijon
-
Dalida Messages postés 7114 Statut Contributeur -
Dalida Messages postés 7114 Statut Contributeur -
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>";
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>";
A voir également:
- Pb avec tableau
- Tableau word - Guide
- Tableau ascii - Guide
- Trier un tableau excel - Guide
- Imprimer un tableau excel - Guide
- Tableau croisé dynamique - Guide
3 réponses
salut,
il faut tester le résultat de 'mysql_fetch_array()' directement dans la condition du 'while()'
pense à utiliser le bouton "Conserver la mise en forme du texte sélectionné" pour mettre en forme ton code, merci !
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 !
mais il faut aussi modifier la première boucle !
et le bouton pour le code, c'est celui-là !
-;o)
<?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)
<?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;
?>