Gestion checkbox avec php

bonjour à tous

J'ai un petit problème pour récupérer les valeures des checkbox..

voici le mode de générationdes dynamique de checkbox da,s mon formulaire

echo "<input type= \"checkbox\" name =\"etat[]\" value =\"$i\" ></th>";

ainsi, je voudrais que la valuer de $etat [$j] soit $i, lorsque la $i est cochée

J'ai 2 bouton de type submit, qui son Supprimé, et réponse

Si je coche 2 case et que je clique sur supprimé par exemple, voici ce que le code

for ($j = 0; $j <= $nbr_entrees ; $j++)
if ($etat[$j] != "") echo " etat[$j]= $etat[$j] <br>";

me donne :
etat[0]= 10
etat[1]= 11supprimer=Supprimer
etat[2]= 10
etat[3]= 11

Alors que etat[2]= 10 et etat[3]= 11 me suffirait, j'ai 4 lignes, avec c'elle là etat[1]= 11supprimer=Supprimer ?

Si quelque a une idée d'où cela vient ..
D'avance merci de votre temps
Configuration: Windows XP
Internet Explorer 7.0

3 réponses

  1. Il faudrait le code source HTML du formulaire qui a généré ce résultat.
    Et donne le code PHP qui précède ton for : comment récupères-tu $nbr_entrees ? etc ...
    Et ce serait royal si tu pouvais donner la sortie d'un
    print_r($_GET)
    [ ou $_POST si c'est en post) ] également (mais si c'est trop compliqué, laisse tomber).
    0
    1. Merci pour ton aide, voici le code enier

      <?php
      include("parametres.php");

      $DB_link = mysql_connect($host,$user,"");
      $requette = " select * from $table where actif = '1' order by date desc, heure desc ";

      $resultat = mysql_db_query($database,$requette,$DB_link);
      $nbr_entrees = mysql_num_rows($resultat);
      $a = array();

      function affichage_unique($var)
      {
      echo "<tr bgcolor=\"#CCCCCC\">";
      //Date
      $tmp = $var;
      echo "<th width=\"10%\" align=left nowrap>".$tmp."</th>";
      //email
      echo "<th width=\"12%\" align=left nowrap>".$tmp."</th>";
      //Type de Message
      echo "<th width=\"8%\" align=left nowrap>".$tmp."</th>";
      //Message
      echo "<th width=\"500\" align=left nowrap>".$tmp."</th>";
      //Bouton Repondre
      echo "<th width=\"8%\" align=left nowrap>".$tmp."</th>";
      //Bouton Supprimer
      echo "<th width=\"8%\" align=left nowrap>".$tmp."</th></tr>";

      };

      ?>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <title>Listing des entrée dans la base : </title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <style type="text/css">
      <!--
      body { font-family: Verdana; font-size: 12px; font-weight: normal; color: #000000;}
      A:link { font-family: Verdana; font-size: 12px; font-weight: bold; color: #000000}
      A:active { font-family: Verdana; font-size: 12px; font-weight: bold; color: #000000}
      A:visited { font-family: Verdana; font-size: 12px; font-weight: bold; color: #000000}
      .title { font-family: Verdana; font-size: 14px; font-weight: bold; color: #404040; text-decoration: none;}
      .menu { font-family: Verdana; font-size: 12px; font-weight: normal; color: #000000; text-decoration: none;}
      .texte { font-family: Verdana; font-size: 12px; font-weight: normal; color: #000000; text-decoration: none;}
      .com { font-family: Verdana; font-size: 12px; font-weight: bold; color: #000000}
      .minitxt { font-family: Verdana; font-size: 9px; font-weight: normal; color: #000000; text-decoration: none;}
      .minitxtred{ font-family: Verdana; font-size: 9px; font-weight: normal; color: #FF0000; text-decoration: none;}
      .special { font-family: Verdana; font-size: 8px; font-weight: normal; color: #595959; text-decoration: none;}
      --></style>

      </head>

      <body>

      <table class="texte" width="100%" border=0 cellspacing=1 cellpadding=2>
      <form name="listing" action="<?php echo $PHP_SELF;?>" method="post" >
      <tr bgcolor="#FF8F15">
      <td class="title" align=center colspan=6> <a class="minitxt" href="listing.php">Le
      Sirroco Listing</a><br>
      <a class="com" href="index.php">Retour
      à la page d'accueil</a> : <a class="com" href="contact.php">Contact</a>
      </td>
      </tr>
      <tr bgcolor="#FFEAD5">
      <th align=left width="1%" nowrap></th>
      <th align=left width="9%" nowrap>Date</th>
      <th align=left width="15%" nowrap>Adresse mail/N° Tel</th>
      <th align=left width="10%" nowrap>Type de message</th>
      <th align=left width="40%" nowrap>Messages <input type="submit" name = "supprimer" value="Supprimer"> <input type="submit" name ="repondre" value="répondre">  </th>
      <th align=left width="8%" nowrap> Statut</th>

      </tr>

      <?php

      if ($nbr_entrees != 0)
      {
      for ($i = 1; $i <= $nbr_entrees ; $i++)
      { //################################affichage_listing($resultat,$DB_link,($i -1));
      $i--;
      echo "<tr bgcolor=\"#CCCCCC\">";
      // Selection
      echo "<th align=left width=\"2%\" nowrap><input type= \"checkbox\" name =\"etat[]\" value =\"$i\" ></th>";

      //Date
      $tmp = mysql_result($resultat,$i,"date");
      $tmp = $tmp."[".mysql_result($resultat,$i,"heure")."]";

      echo "<th width=\"9%\" align=left nowrap>".$tmp."</th>";
      //email
      $tmp = mysql_result($resultat,$i,"email");
      echo "<th width=\"12%\" align=left nowrap>".$tmp."</th>";

      //Type de Message
      if (mysql_result($resultat,$i,"reservation")) $tmp = "Reservation";
      else $tmp = "Avis";
      echo "<th width=\"8%\" align=left nowrap>".$tmp."</th>";
      //Message
      $tmp = mysql_result($resultat,$i,"message");
      echo "<th width=\"500\" align=left nowrap>".$tmp."</th>";

      //Bouton Repondre
      $j = $i +1;
      echo "<th width=\"8%\" align=left nowrap><a href=\"repondre.php?indice=$i\"> <img src=\"images/Circle_Green.gif\" border =\"0\" width=\"12\" > [$j]</a></th>";
      //Bouton Supprimer
      //echo "<th width=\"8%\" align=left nowrap><a href=\"supprimer.php?indice=$i\"> Supprimer </a></th></tr>";
      //################################}
      $i++;
      };
      //for ($i = 11; $i <= $nbr_entrees ; $i++)
      //{
      //$indice = $i - 1;
      //$delete_email = mysql_result($resultat,$indice,"email");
      //$delete_heure = mysql_result($resultat,$indice,"heure");
      //$requette2 = "delete from $table where email = '$delete_email' and heure = '$delete_heure'";
      //mysql_db_query($database,$requette2,$DB_link);

      //};

      mysql_close($DB_link);

      }
      else affichage_unique("tbl vide");

      ?>
      </form>
      </table>
      <p>---------------------------------------------------------------------------------------------------------------------------------------------------------------</p>
      <p>Liste des indice selectionnés : </p>
      <p>

      <?php

      if (isset($supprimer))
      {
      echo "SUP <br>";
      };

      if (isset($repondre))
      {
      echo "REP <br>";
      };

      for ($j = 0; $j < $nbr_entrees ; $j++)
      if ($etat[$j] != "") echo " etat[$j]= $etat[$j] <br>";
      ?>
      </body>
      </html>
      0
      1. Ca a l'air correct...

        Essaie de me mettre le code HTML de ta page qui contient le formulaire, et fais un
        print_r($_POST)
        après
        for ($j = 0; $j < $nbr_entrees ; $j++)
        if ($etat[$j] != "") echo " etat[$j]= $etat[$j] <br>"; 

        Et donne le résultat
        0