Derek Derek - 2 years ago 125
SQL Question

PHP Syntax for webpage radio buttons

Currently I have the following table in my database


and written the following php script

while ($list = mysql_fetch_assoc($result))
echo $list['QuestionID'] . ":" . $list['QuestionText'] . "<br/>";
$optionsquery="SELECT AnswerText,AnswerID FROM Options Where QuestionID=".$questionID;
$optionsresult=mysql_query($optionsquery) or die ('Query failed:'. mysql_error());
while($row = mysql_fetch_array($optionsresult))
'Display the multiple choices
associating the AnswerID with the appropriate AnswerText.'

E.g. echo "<input type='radio' name='QuestionID'
corresponding AnswerText given the AnswerID;

E.g for the first radio button:

echo "<input type='radio' name='2' value='21'/> User;


Could I get help with the PHP syntax for the radio buttons?

Answer Source

You could do:

echo "<input type='radio' id='radio-" . $row["QuestionID"] . "-" . $row["AnswerID"] . "' name='" . $row["QuestionID"] . "' value='" . $row["AnswerID"] . "' /> <label for='radio-" . $row["QuestionID"] . "-" . $row["AnswerID"] . "'>" . $row["AnswerText"] ."</label><br/>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download