Bonjour à tous,
Je viens vers vous pour solliciter vos compétences suite à un problème rencontré.
Je suis en train de créer un formulaire pour réserver un/des paniers de bouffe avec choix du contenu.
Pour le formulaire de choix :
panier 1 (input checkbox pour sélectionner ce panier)
quantité (input number pour ce panier)
liste des produits dans ce panier (input checkbox pour sélectionner les produits)
panier 2 (input checkbox pour sélectionner ce panier)
quantité (input number pour ce panier)
liste des produits dans ce panier (input checkbox pour sélectionner les produits)
panier 3 (input checkbox pour sélectionner ce panier)
quantité (input number pour ce panier)
liste des produits dans ce panier (input checkbox pour sélectionner les produits)
Code :
- $organics_query = query("select c.organic_id, c.sort_order, ci.organic_name, c.status, ci.languages_id
- from TABLE_ORGANIC c, TABLE_ORGANIC_INFO ci
- where c.organic_id = ci.organic_id
- and c.status = '1'
- and ci.languages_id = '4'
- ORDER BY c.sort_order, ci.organic_name" );
- while ($organic = fetch_array($organics_query)) {
- echo '<div style=" border-width:1px; border-style:solid; border-color:#000; vertical-align:top; text-align:center; display:inline-block; width:250px; margin: 10px; padding:10px;" >';
- // choix du panier
- echo ' <div style=" height:300px; vertical-align:top; text-align:center;">'
- .'<strong>'.TEXT_SELECT_ORGANIC.'</strong><input type="checkbox" name="idProduit['.$organic['organic_id'].']" value="'.$organic['organic_id'].'">'.$organic['organic_name']
- .'<br>'.
- '</div>';
- // choix des produits dans le panier
- echo ' <div style=" vertical-align:top; text-align:left;"><strong>'.TEXT_SELECT_INSIDE.'</strong><br>';
- $organic_products_query = query("select *
- from TABLE_ORGANIC_PRODUCTS
- where organic_id = '" . $organic['organic_id'] . "'
- ORDER BY organic_products_id" );
- while($organic_products = fetch_array($organic_products_query)){
- echo '<input type="checkbox" name="pID['.$organic_products['products_id'].']" value="'.$organic_products['products_id'].'" checked="true">'.$organic_products['products_id'].'<br>';
- }
- echo '</div>';
- // choix de la quantité
- echo ' <br><div style=" vertical-align:top; text-align:left;"><strong>'.TEXT_SELECT_QTY.'</strong>
- <input type="number" min="1" max="99" style="width: 7em;" autocomplete="off" name="quantite['.$organic['organic_id'].']" id="'.$organic['organic_id'].'" value=""/>
- </div>
- </div>';
- }
|
et pour envoyer tout ça dans le contenu d'un mail :
Code :
- if(isset($_POST['idProduit'])){
- foreach ($_POST['idProduit'] as $key => $idProduit){
- $sql = query("select c.organic_id, c.sort_order, ci.organic_name, c.status, ci.languages_id
- from TABLE_ORGANIC c, TABLE_ORGANIC_INFO ci
- where c.organic_id = ci.organic_id
- and c.status = '1'
- and ci.languages_id = '4'
- and c.organic_id =".$idProduit."
- " );
- $recup = fetch_array($sql);
- foreach ($_POST['pID'] as $pID){
- $sql2 = query("select *
- from TABLE_ORGANIC_PRODUCTS
- where organic_id = '".$idProduit."'
- and products_id = '" . $pID . "'
- " );
- $recup2 = fetch_array($sql2);
- $organic_prod .= $recup2['products_id'].', ';
- }
- $organic_materials .= $recup['organic_name'].' x '.$_POST['quantite'][$key].' : '.$organic_prod.' </br> ';
- }
- }
- $contenu_email = $organic_materials;
|
Je souhaite obtenir cela :
"nom du panier" x "quantité" : "liste des id de produits"
Le résultat obtenu avec ma formule :
Panier n°2 x 1 : , , , 4363, 4365, 4404, , ,
Panier n°3 x 1 : , , , 4363, 4365, 4404, , , , , , , , , 1239, 1943, 536
Le résultat souhaité :
Panier n°2 x 1 : 4363, 4365, 4404
Panier n°3 x 1 : 1239, 1943, 536
Le problème vient de mon imbrication de foreach.
Pouvez vous me dire ce qui ne va pas dans ma formule ou m'orienter vers une autre solution.
Merci à vous de prendre le temps de regarder.
Bonne fin de journée
Hugo_064
Message édité par hugo_064 le 16-11-2017 à 12:36:35