Multiple checkboxes

houssam_ballout

New Member
Hello all,
I'd multiple checkboxs and radio buttons , and they are generated automatically based on the database that I'd (mysql)..

on my page, I had queried all the questions and number of options, part of the code that I think you need is:

for($i=1;$i<=$NbOptions;$i++)
{
if($MultiAnswer == 'yes')
{
echo "<input type='checkbox' name='box[]' value='$idQuestion_$i' />" . $row2['option'.$i];
echo "<br />";
}

else
{
echo "<input type='radio' name='box[]' value='' />" . $row2['option'.$i];
echo "<br />";
}


}

when I press save ,
I use
if(isset($_POST['save']))

//here I want to loop through all the box[]?
and see if its checked or no
 
So you are looking for how to loop though it?

I think you'd want to do something like this:
Code:
for ($i = 0; $i < count($_POST['box']; $i++){
  if (isset($_POST['box'][$i])){
    //do stuff
  }
}
 
Back
Top