IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Problème avec les checkbox dynamiques


Sujet :

Langage PHP

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 1
    Points : 1
    Points
    1
    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 : 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

  2. #2
    Membre expérimenté
    Avatar de muad'dib
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2003
    Messages
    1 011
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2003
    Messages : 1 011
    Points : 1 375
    Points
    1 375
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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é

  3. #3
    Membre averti Avatar de makmaoui
    Profil pro
    Développeur Web
    Inscrit en
    Mai 2007
    Messages
    283
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mai 2007
    Messages : 283
    Points : 368
    Points
    368
    Par défaut
    Salut,

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

    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>


    et ton fichier 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=$_POST[choix] ORDER BY nom_prod";
    $result = mysql_query($rq)
    or die ("Exécution Impossible");
     
    ?> 
    </body>
    </html>

Discussions similaires

  1. JTable : problème avec les checkbox dans les colonnes
    Par oelydina dans le forum Composants
    Réponses: 2
    Dernier message: 04/11/2008, 22h40
  2. [AIDE] Problème avec les CheckBox
    Par Diablo_22 dans le forum Struts 1
    Réponses: 4
    Dernier message: 09/10/2008, 11h46
  3. Problème avec les checkbox
    Par yaya0057 dans le forum Struts 1
    Réponses: 2
    Dernier message: 19/07/2007, 15h16
  4. Problème avec les checkbox
    Par presteus dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 25/07/2006, 01h06
  5. Problème avec les libraires dynamiques
    Par Harzoglups dans le forum C
    Réponses: 3
    Dernier message: 17/01/2006, 15h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo