That's happening because all of your radio button sets have the same name: item
. Here are a couple ways you can make the radio button sets unique; pick the one that's best for you.
Append the
poll.id
value to each button name:$result2 = mysql_query("SELECT * FROM optie WHERE poll ='" . $data['id'] . "'"); while($data2 = mysql_fetch_assoc($result2)){ echo"<input type='radio' name='item_" . $data['id'] . "' value='" . $data2['id'] . "'/>" . $data2['optie'] . "<br />"; }
Append a sequence number to each button name:
$result2 = mysql_query("SELECT * FROM optie WHERE poll ='" . $data['id'] . "'"); $buttonNumber = 0; while($data2 = mysql_fetch_assoc($result2)){ ++$buttonNumber; echo"<input type='radio' name='item_$buttonNumber' value='" . $data2['id'] . "'/>" . $data2['optie'] . "<br />"; }
Finally, note that the mysql_query
family of functions is deprecated because it can leave you vulnerable to SQL Injection attacks. See here and other places for information about using mysqli
or PDO
instead.