[英]Radio type: same name with option number PHP
I have for example 1 questions and 2 option field in which each of the field would have a radio button to indicate whether that option is the correct answer or not.例如,我有 1 个问题和 2 个选项字段,其中每个字段都有一个单选按钮来指示该选项是否是正确答案。
echo"<p>Enter Question:<input type=\"text\" name=\"question[]\" size=\"40\" maxLength=\"1000\" >";
Option 1:<input type=\"text\" name=\"option[$num][]\" size=\"40\" maxLength=\"100\"> <input type=\"radio\" name=\"weight[$question_num][]\" data-role=\"none\" style=\"text-align:justify\">Correct answer</p></br>";
Option 2:<input type=\"text\" name=\"option[$num][]\" size=\"40\" maxLength=\"100\"> <input type=\"radio\" name=\"weight[$question_num][]\" data-role=\"none\" style=\"text-align:justify\">Correct answer</p></br>";
Both of the radio button is in a group so it works prefectly fine.两个单选按钮都在一个组中,因此可以正常工作。 However, in the back end server:
但是,在后端服务器中:
if (isset($_POST['weight'])) {
print_r($_POST['weight']);
foreach ($_POST['weight'] as $key => $weighteach) {
foreach ($weighteach as $key2 => $value) {
echo"<br/>";
$key2= $key2+1;
echo $key.':'.$key2;
echo"<br/>";
}
}
}
I'm trying to echo Question Number: Option Number of the radio button I selected before I store into my DB.我正在尝试回显问题编号:我在存储到数据库之前选择的单选按钮的选项编号。 But even if I selected Option2, the output will be 1:1 instead of 1:2.
但即使我选择了 Option2,输出也会是 1:1 而不是 1:2。 Please help me to the best that you can.
请尽你所能帮助我。 Will greatly appreciate it.
将不胜感激。
You have not given your radio buttons values:你没有给你的单选按钮值:
<input type=\"radio\" name=\"weight[$question_num][]\" data-role=\"none\" style=\"text-align:justify\">
should be something like:应该是这样的:
<input type=\"radio\" name=\"weight[$question_num][]\" value='Value of radio button 1' data-role=\"none\" style=\"text-align:justify\">
Now you can get the value of the selected radio button in php.现在您可以在 php.ini 中获取所选单选按钮的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.