PHP CheckBox

Résolu
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. 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
    1. 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. 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