Bonjour,
pour mon application qui affiche plusieurs menu de la base de données dans un tableau avec des cases a cocher, j'aimerais que pour chaque checkbox choisie, on sauvegarde les valeurs et affiche dans la facture, mais c'est toujours le dernier choix de mes checkbox qui viennent et non tous les choix.
Images d'illustration:
code du tableau:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>eGEST-RMB</title>
<link href="Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="menu2.css" />
</script>
<style type="text/css">
</head>
<body>
<?php
if(isset($_POST['reserver']))
{
if(!empty($_POST['choix']))
{
$i=0;
foreach($_POST['choix'] as $language)
{
header("Location:facture.php?design=".$language);
}
}
else
{
echo "<label class='text-danger'> Selectionner un article </label>";
}
}
?>
<table class ="bloc_page" width="969" align="center">
<tr>
<td width="961" height="71" bgcolor="#000099"><div align="center" class="Style1">* RMB * </div>
<div align="center"></div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"></td>
</tr>
<tr>
<td height="12" bgcolor="#FFFF00"><div align="center" class="Style13"><a href="index.php"><img src="photoshop/optimiser-page-accueil-blog.png" width="21" height="27" border="0" align="left" /></a> <div align="center" class="Style13 Style14" >Consulter le menu <a href="voir_menu.php"></a></div>
</div></td>
</tr>
<tr>
<td height="490" align="center" valign="top" background="photoshop/font.jpg" class="font" >
<form id="form1" name="form1" method="post" action="consultation.php">
<table class="bloc_page" width="897" border="1" bordercolor="#419FDF">
<tr bgcolor="#000099" class="Style1">
<td colspan="4"><div align="center">Nourriture</div></td>
</tr>
<tr bgcolor="#000099" class="Style1">
<td width="261"><div align="center" class="Style19">Désignation</div></td>
<td width="190"><div align="center" class="Style19">Prix Unitaire </div></td>
<td width="264"><div align="center" class="Style19">En savoir plus </div></td>
<td width="154"><div align="center">Commander</div></td>
</tr>
<?php
require('config.php');
$retour = mysql_query("SELECT * FROM nourriture ");
while ($donnees = mysql_fetch_array($retour)){
$design = $donnees['design'];
$prix = $donnees['prix'];
$comment = $donnees['comment'];
?>
<tr class="Style13">
<td><div align="center" class="Style21"> <strong><?php echo $design; ?></strong></div></td>
<td><div align="center" class="Style22"><strong><?php echo $prix; ?></strong></div></td>
<td><div align="center" class="Style22"><strong> <?php echo $comment; ?> </strong></div></td>
<td><div align="center">
<label></label>
<label>
<input type="checkbox" name="choix[]" value="<?php echo $design; ?>" />
</label>
</div></td>
</tr>
<?php } ?>
</table>
<table class="bloc_page" height="80" width="897" border="0" >
<tr>
<td> <div align="right">
<label>
<input name="reserver" type="submit" id="reserver" value="Reserver" />
</label>
</div></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
code de la facture:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
<link href="Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="menu2.css" />
</script>
<script type="text/javascript" src="page.js"></script>
</head>
<body>
<table class ="bloc_page" width="969" align="center">
<tr>
<td width="961" height="71" bgcolor="#000099"><div align="center" class="Style1">* RMB * </div>
<div align="center"></div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"></td>
</tr>
<tr>
<td height="32" bgcolor="#FFFF00"><div align="center" class="Style13"><a href="index.php"><img src="photoshop/optimiser-page-accueil-blog.png" width="21" height="27" border="0" align="left" /></a> <div align="center" class="Style13 Style14" >Facture<a href="voir_menu.php"></a> <a href="consultation.php"><img src="photoshop/fermer.jpg" width="21" height="27" border="0" align="right" /></a></div>
</div></td>
</tr>
<tr>
<td height="490" align="center" valign="top" background="photoshop/font.jpg" class="font" >
<form id="form1" name="form1" method="post" action="">
<table width="897" border="1" bordercolor="#7AC3EC" class="bloc_page" >
<tr bgcolor="#000099" class="Style1">
<td colspan="5" bordercolor="#B3E0F7" bgcolor="#E3F2F9"><div align="center" class="Style13">Nourriture</div></td>
</tr>
<tr bgcolor="#E3F2F9" class="Style1">
<td width="265" bgcolor="#E3F2F9" class="Style21"><div align="center" class="Style21">Désignation </div></td>
<td width="158" bgcolor="#E3F2F9" class="Style21"><div align="center" class="Style21">Prix Unitaire </div></td>
<td width="151" bgcolor="#E3F2F9" class="Style21"><div align="center" class="Style21">Quantité</div></td>
<td colspan="2" class="Style21"><div align="center" class="Style21">Montant </div> <div align="center" class="Style30"></div></td>
</tr>
<?php
$design= $_GET['design'];
?>
<tr class="Style13">
<td id="design"><div align="center"><?php echo $design; ?></div></td>
<td id="pu" ><div align="center"></div></td>
<td id="qte" contenteditable onkeypress="validate(event)" onkeyup="calcul()"><div align="center">
<label>
<input name="qte" type="number" 1="" />
</label>
</div></td>
<td id="montant"> <div align="center" id="affichage"> <script language="text/javascript"> document.getElementById('montant').innerHTML = Math.round(montant * 100) / 100;
</script>
</div></td>
</tr>
<tr class="Style13">
<td colspan="2"> </td>
<td><span class="Style21">Sous - total : </span></td>
<td> </td>
</tr>
<tr class="Style13">
<td colspan="2"></td>
<td class="Style21">Montant Total : </td>
<td width="295"> </td>
</tr>
</table>
</form>
<p> </p></td>
</tr>
</table>
<p> </p>
</body>
</html>
correction des balises de code pour y ajouter la coloration syntaxique....... encore.......
Afficher la suite
18 juil. 2018 à 14:04
J'ai pu recuperer toutes les designations choisies depuis les chechbox.
Maisj'aimerais aussi savoir comment prendre les prix correspondants aux designations choisies?
voici le code php:
18 juil. 2018 à 14:06
Il m'affiche seulement les designations. Comment afficher aussi les prix correspondants?
18 juil. 2018 à 15:06
Si tu ne sais pas comment faire, regarde ici : https://codes-sources.commentcamarche.net/forum/affich-10086941-amelioration-procedure-balises-de-code#11
Ensuite,
- le session_start doit être placé au tout début de ton code php.
- Il serait bien de récupérer PROPREMENT les variables AVANT de les utiliser.
Je t'invite à lire et à appliquer ceci : http://www.commentcamarche.net/faq/48399-php-gestion-des-erreurs-debogage-et-ecriture-du-code
- il faut stocker, dans ta variable de session toutes les informations dont tu as besoin ensuite sur ta facture...