Bonjour,
Dans ma base de donnée j'ai deux tables catégories et produits .
je cherche a creer un checkbox dynamique de telle maniére que chaque catégorie s'affiche avec la liste de produits qui lui corespond . sauf que ma variable choix[] n'est pas prise en compte.
voici le code de commande.php
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 <!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>
<style type="text/css">
<!--
.style1 {
	font-size: 18px;
	font-weight: bold;
}
-->
</style>
</head>
<body BGCOLOR="#ffffff" LINK="navy" VLINK="red" text="black" alink="maroon" leftmargin="0" topmargin="0" 
background="../Images/fond.JPG">
<body>
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="style1">Quel est la catégorie de produits qui vous interésse ?</span>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Choisissez-la dans la liste ci- dessous :
<p>	
  <? include("connexion.php") ?> 
  <?php
$rq = "SELECT DISTINCT nom_cat,id_cat FROM categorie ORDER BY nom_cat,id_cat";
$result = mysql_query($rq)
 or die ("Exécution Impossible");
echo "<div style = 'margin-left : .lin'>";
// création du formulaire 
echo "<form action='commande2.php' method='post' >\n";
echo "<center><table cellpadding ='5' border ='1'>";
$compteur = 1 ;
while ($ligne = mysql_fetch_array($result) )
{ 
  extract($ligne);
  echo "<tr><td valign='top' width='15%'>\n";
  echo "<input type = 'radio' name ='choix[]' value='$nom_cat' \n"; 
  if ($compteur == 1 ) 
  { 
  echo "Checked" ;
  }
  echo "><font size='+1'><b>$nom_cat</b></font>
  </td>
  <td>$id_cat</td> 
  </tr>";
  $compteur++;
  }
  echo "</table>";
  echo "<p><center><input type='submit' value='Faites votre choix'>
  </form>\n";
 
 
  ?>
 
 
 
</body>
</html>
Puis j'aurai voulu rècuperer le choix de catégorie de l'utilisateur afin d'afficher la liste de produits correspondants a la catégorie choisi .
voici le code de commande2.php
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
<!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>
<style type="text/css">
<!--
.style1 {
	font-size: 18px;
	font-weight: bold;
}
-->
</style>
</head>
<body BGCOLOR="#ffffff" LINK="navy" VLINK="red" text="black" alink="maroon" leftmargin="0" topmargin="0" 
background="../Images/fond.JPG">
<body>
<? include("connexion.php") ?>        
<? include("commande.php")  ?>
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="style1">Quel sont les produits qui vous interésse ?</span>
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="style1">Choissisez ci dessous : </span>
<?php
$rq = "SELECT DISTINCT nom_prod  FROM produit where $id_cat=isset($choix[]) ORDER BY nom_prod";
$result = mysql_query($rq)
or die ("Exécution Impossible");
 
?> 
</body>
</html>
Je sais que c'est long mais s'il vous plait aidez moi . merci d'avance