PHP CheckBox

Résolu
PacSuperfly -  
maka54 Messages postés 721 Statut Membre -
Bonjour,

Voici mon probleme :
while($row1 = mysql_fetch_assoc($result))
{
echo "<input type='checkbox' name='ingredients[]' id='ingredients' value='".$row1['prix']."' />";
echo $row1['ingredient']." ".$row1['prix']."&nbsp CH";
echo '<br>';
}

Comment faire pour ajouter ' checked=checked' ?

Merci beaucoup pour votre aide.
Paulo

2 réponses

  1. PacSuperfly
     
    Merci pour ta reponse , mais si je fais ça et comme c'est dans une boucle ça va mettre toutes les options a Checked ....
    1
    1. maka54 Messages postés 721 Statut Membre 80
       
      while($row1 = mysql_fetch_assoc($result)) 
      { 
          $checked =''; 
          if(condition == true){ 
              $checked = ' checked="checked"'; 
         } 
         echo '<input type="checkbox" name="ingredients[]" id="ingredients" value="'.$row1['prix'].'"'.$checked.' />'; 
      }


      voilà comment faire
      0
  2. maka54 Messages postés 721 Statut Membre 80
     
    echo '<input type="checkbox" name="ingredients[]" id="ingredients" value="'.$row1['prix'].'" />';


    à ta place, j'écrirais plutot comme çà inversé la simple et la double quote et
    checked="checked" 
    devrait marcher soit :

    echo '<input type="checkbox" name="ingredients[]" id="ingredients" value="'.$row1['prix'].'" checked="checked" />';
    0