Bonjour tout le monde,
j'essaye de récupérer les valeurs de checkbox à travers un tableau de données, mais je pense que la syntaxe n'est pas la bonne,
sachant que l'user choisi des produits et les commande par la suite :
voilà mon code:
code sql
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 <?php $tri_critere = isset($_POST['trier']) ? trim($_POST['tri_critere']) : ""; $cocher = isset($_POST['tri']) ? trim($_POST['checkbox']) : "id_produit"; $liste = sqlListerCategoriesProduits($conn,$tri_critere,$cocher); $listeCategories=sqlLireCategorie($conn); ?> <form action="test.php" method="get"> <?php if (count($liste) > 0) : ?> <table> <tr> <th>Produit</th> <th>Description</th> <th>Prix</th> <th>Marque</th> <th>categorie</th> <th>Commander</th> </tr> <?php foreach ($liste as $row) : ?> <tr> <td><?php echo $row['nom_produit'] ?></td> <td><?php echo $row['description_produit'] ?></td> <td><?php echo $row['prix_produit'] ?></td> <td><?php echo $row['nom_marque'] ?></td> <td><?php echo $row['nom_categorie_produit'] ?></td> <td> <input type="checkbox" name="checkbox[]" value="'.$row['id_produit'].'"> </td> </tr> <?php endforeach; ?> </table> <?php else : ?> <p>Aucun produit trouvé trouvé.</p> <?php endif; ?> <a href="test.php"><input type="submit" name="envoi" value="Commander"></a> </form>
page test pour afficher le résultat coché
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 function sqlListerCategoriesProduits($conn,$trier,$cocher){ $req = "SELECT * FROM categories_produits cp INNER JOIN produits p on cp.id_categorie_produit = p.id_categorie_produit INNER JOIN marques m ON p.id_marque = m.id_marque"; if(!empty($trier)){ $req.=" and cp.id_categorie_produit =".mysqli_real_escape_string($conn,$trier); } if(!empty($cocher)){ $req.=" and p.id_produit =".mysqli_real_escape_string($conn,$cocher); } if($result = mysqli_query($conn,$req,MYSQLI_STORE_RESULT)){ $nbResult = mysqli_num_rows($result); $liste = array(); if ($nbResult) { mysqli_data_seek($result, 0); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $liste[] = $row; } } mysqli_free_result($result); return $liste; } else { errSQL($conn); exit; } }
de l'aide SVP!!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 <?php $tri_critere = isset($_POST['trier']) ? trim($_POST['tri_critere']) : ""; $cocher = isset($_POST['tri']) ? trim($_POST['checkbox']) : "id_produit"; $liste = sqlListerCategoriesProduits($conn,$tri_critere,$cocher); ?> <form method="get" action="test.php"> <table> <tr> <th>Numéro</th> <th>Produit</th> <th>Descrption du produit</th> <th>Prix du produit</th> <th>Quantité du produit</th> <th>Catégorie du produit</th> <th>Marque du produit</th> </tr> <?php foreach ($liste as $row) : ?> <tr> <td><?php echo $row['id_produit'] ?></td> <td><?php echo $row['nom_produit'] ?></td> <td><?php echo $row['description_produit'] ?></td> <td><?php echo $row['prix_produit'] ?></td> <td><?php echo $row['quantite_produit_commande'] ?></td> <td><?php echo $row['nom_categorie_produit'] ?></td> <td><?php echo $row['nom_marque'] ?></td> </tr> <?php endforeach; ?> </table> <input type="text" name="submit" value="confirmer la commande"> </form>
Partager