Précédent   Forum des professionnels en informatique > PHP > Langage > Formulaires
Formulaires Forum d'entraide sur les formulaires avec PHP. Avant de poster -> FAQ formulaires, Cours de formulaires et Sources de formulaires
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 17/05/2007, 17h35   #1
Invité de passage
 
Inscription : mai 2007
Messages : 1
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 1
Points : 0
Points : 0
Par défaut Problème avec les checkbox dynamiques

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 :
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 :
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
20304995 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/05/2007, 17h59   #2
Membre chevronné
 
Avatar de muad'dib
 
Inscription : janvier 2003
Messages : 881
Détails du profil
Informations personnelles :
Âge : 30

Informations forums :
Inscription : janvier 2003
Messages : 881
Points : 780
Points : 780
Code :
echo "<input type = 'radio' name ='choix' value='$nom_cat' \n";
puis pour récupérer la valeur

aura la valeur du $nom_cat sélectionné
__________________
Pour une bien meilleur lisibilité, utilisez la balise [code], c'est le [#] dans l'éditeur de message.
Pensez à la balise
Mon site dédié au jeu d'échecs - Logiciel de suivi d'entrainement de musculation gratuit
muad'dib est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/05/2007, 18h00   #3
Membre éclairé
 
Avatar de makmaoui
 
Développeur Web
Inscription : mai 2007
Messages : 282
Détails du profil
Informations personnelles :
Âge : 26
Localisation : France, Nord (Nord Pas de Calais)

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : mai 2007
Messages : 282
Points : 361
Points : 361
Salut,

dans ton fichier commande.php remplace ton code par celui-ci :

Code :
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>


et ton fichier commande2.php :

Code :
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=$_POST[choix] ORDER BY nom_prod";
$result = mysql_query($rq)
or die ("Exécution Impossible");
 
?> 
</body>
</html>
makmaoui est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h37.


 
 
 
 
Partenaires

Hébergement Web