Php 如何在同一while循环中选择多个单选按钮,该循环从数据库中回响
guyz,我想为每个问题选择单选按钮。请帮助我这样做。现在我只能在一个页面中选择一个单选按钮。。。。。。检查此链接:Php 如何在同一while循环中选择多个单选按钮,该循环从数据库中回响,php,mysql,forms,Php,Mysql,Forms,guyz,我想为每个问题选择单选按钮。请帮助我这样做。现在我只能在一个页面中选择一个单选按钮。。。。。。检查此链接: while($row=mysql\u fetch\u row($rs)){ 回声“; 回声“; $n=$n+1; 回应“问题”。$n.:$row[2]”; 回显“$row[3]”; 回显“$row[4]”; 回显“$row[5]”; 回显“$row[6]”; } 如何获取数据并将其存储到mydb $query="select * from question";
while($row=mysql\u fetch\u row($rs)){
回声“;
回声“;
$n=$n+1;
回应“问题”。$n.:$row[2]”;
回显“$row[3]”;
回显“$row[4]”;
回显“$row[5]”;
回显“$row[6]”;
}
如何获取数据并将其存储到mydb
$query="select * from question";
$rs=mysql_query("select * from question where testid=$tid",$cn) or die(mysql_error());
if($submit=='Get Result')
{
$n=0;
while($row= mysql_fetch_row($rs)){
for($i=0;$i<count($_POST['ques']);$i++)
{
$ans=$_POST['ques'][$n][$i];
echo $ans;
$n=$n+1;
mysql_query("insert into useranswer(sessid, testid, ques, ans1,ans2,ans3,ans4,correctans,yourans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());}
}
}
$query=“从问题中选择*”;
$rs=mysql\u查询(“从testid=$tid的问题中选择*,$cn)”或die(mysql\u错误());
如果($submit=='Get Result')
{
$n=0;
而($row=mysql\u fetch\u row($rs)){
对于($i=0;$i只需将ques[]
替换为ques[“$n.”][]
如下
while($row= mysql_fetch_row($rs)){
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques[".$n."][]' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques[". $n ."][]' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques[". $n ."][]' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques[". $n ."][]' value=4>$row[6]";
}
while($row=mysql\u fetch\u row($rs)){
回声“;
回声“;
$n=$n+1;
回应“问题”。$n.:$row[2]”;
回显“$row[3]”;
回显“$row[4]”;
回显“$row[5]”;
回显“$row[6]”;
}
您必须为每套单选按钮命名
while($row=mysql_fetch_row($rs)) {
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques".$n."' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=4>$row[6]";
echo "</table></table></form>"; //AND you should close your tags
}
while($row=mysql\u fetch\u row($rs)){
回声“;
回声“;
$n=$n+1;
回应“问题”。$n.:$row[2]”;
回显“$row[3]”;
回显“$row[4]”;
回显“$row[5]”;
回显“$row[6]”;
echo”“;//您应该关闭标记
}
此外,您应该避免使用mysql_函数,这些函数在PHP7中已被弃用和删除。错误在于您使用相同的名称命名所有单选按钮。这使得所有单选按钮都在一个组中。请使用三个不同的名称命名每个组。您的问题已经解决。您应该使用复选框
进行多次选择。我认为siby是指多组单选按钮。您应该为不同的单选按钮组使用不同的名称属性。即ques[1][],ques[2][].请检查图像link@Xardas:二维数组???这是我之前尝试过的一个。它可以工作,但是。我需要每个问题的数据。然后在开始循环之前写一个,然后在结束循环之后关闭它。谢谢它的工作…但是我需要更多的声誉来接受答案…抱歉…这有效吗??如果($submit=='Get Result'){$n=0;而($row=mysql\u fetch\u row($rs)){$i=$\u POST['$a'];for($i=0;$i请告诉我如何访问以表单形式发送的数据……上面的代码是否正确……我想将其存储在我的数据库中
while($row=mysql_fetch_row($rs)) {
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques".$n."' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=4>$row[6]";
echo "</table></table></form>"; //AND you should close your tags
}