用于网页单选按钮的PHP语法

时间:2012-03-18 05:38:57

标签: php mysql

目前我的数据库中有以下表格

|AnswerID|QuestionID|AnswerText|
|21|2|User|
|22|2|Admin|
|23|2|Guest|
|24|2|User2|

并编写以下php脚本

$questionID=0;
while ($list = mysql_fetch_assoc($result)) 
{
echo $list['QuestionID'] . ":" . $list['QuestionText'] . "<br/>";  
$questionID=$list['QuestionID'];
}
$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'     
              value='AnswerID'/>" 
              corresponding AnswerText given the AnswerID;

   E.g for the first radio button:

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

}

我可以获得单选按钮的PHP语法帮​​助吗?

1 个答案:

答案 0 :(得分:3)

你可以这样做:

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/>";