Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 单选按钮和在测验中检查用户的选择_Mysql_Phpmyadmin_Radio Button_Multiple Choice - Fatal编程技术网

Mysql 单选按钮和在测验中检查用户的选择

Mysql 单选按钮和在测验中检查用户的选择,mysql,phpmyadmin,radio-button,multiple-choice,Mysql,Phpmyadmin,Radio Button,Multiple Choice,我正在制作一个测验系统,并尝试了一种从MySQL获取变量和值的不同方法 $question = mysql_query("SELECT * FROM `questions`"); $stat = mysql_fetch_assoc($question); $num = mysql_num_rows($question); $questionid = 0; for($i=0;$i<=$num;$i++) { $question = mysql_query("SELECT * FROM `qu

我正在制作一个测验系统,并尝试了一种从MySQL获取变量和值的不同方法

$question = mysql_query("SELECT * FROM `questions`");
$stat = mysql_fetch_assoc($question);
$num = mysql_num_rows($question);
$questionid = 0;
for($i=0;$i<=$num;$i++)
{
$question = mysql_query("SELECT * FROM `questions` WHERE `id`='$i'");
$stat = mysql_fetch_assoc($question);
//if($stat['answer'] == null
echo $stat['question'] . '<br />';
echo '<input type="radio" name="' . $i .'" value="' . $questionid . '" />' . $stat['answer1'] . '<br />';
echo '<input type="radio" name="$i" value"$questionid" />' . $stat['answer2'] . '<br />';
echo '<input type="radio" name="$i" value"$questionid" />' . $stat['answer3'] . '<br />';
echo '<input type="radio" name="$i" value"$questionid" />' . $stat['answer4'] . '<br />';
$questionid++;
}

现在,我想让这个人选择正确的答案,但当我在问题1和问题2中选择答案时,可能是因为收音机的名称相同,我不知道如何让学生在每个问题中选择一个答案,以及如何让学生选择将答案存储在一个变量中,并检查答案是否正确。

您对PHP变量有问题,并引用“/”。未正确使用连接运算符

名称='$i.“值=”$疑问号。”

见代码:

for($i=0;$i<=$num;$i++)
{
$question = mysql_query("SELECT * FROM `questions` WHERE `id`='$i'");
$stat = mysql_fetch_assoc($question);
//if($stat['answer'] == null
echo $stat['question'] . '<br />';
echo '<input type="radio" name="' . $questionid .'" value="' . $stat['answer1'] . '" />' . $stat['answer1'] . '<br />';
echo '<input type="radio" name="' . $questionid .'" value="' . $stat['answer2'] . '" />' . $stat['answer2'] . '<br />';
echo '<input type="radio" name="' . $questionid .'" value="' . $stat['answer3'] . '" />' . $stat['answer3'] . '<br />';
echo '<input type="radio" name="' . $questionid .'" value="' . $stat['answer4'] . '" />' . $stat['answer4'] . '<br />';
$questionid++;
}

我不认为你们的方法有那个么好。我认为迭代代码的最好方法是while循环

$all = mysql_query("SELECT * FROM 'questions'");
while($all_array=mysql_fetch_array($all))
{
$question = mysql_query("SELECT * FROM questions WHERE id='".$all_array['id']."'");
while($stat=mysql_fetch_array(question)){
echo $stat['question'] . '<br />';
echo '<input type="radio" name="' .$stat['id'].'" value="' . $stat['answer1'] . '" />' . $stat['answer1'] . '<br />';
echo '<input type="radio" name="' .$stat['id'].'" value="' . $stat['answer2'] . '" />' . $stat['answer2'] . '<br />';
echo '<input type="radio" name="' .$stat['id'].'" value="' . $stat['answer3'] . '" />' . $stat['answer3'] . '<br />';
echo '<input type="radio" name="' .$stat['id'].'" value="' . $stat['answer4'] . '" />' . $stat['answer4'] . '<br />';
}
}

如果每个按钮的值都是$questionid,那么您将不知道按下了什么答案按钮。。。请参阅中的我的答案以获得更完整的答案solution@Floris当前位置我只想到引用。是的,你是对的。每个单选按钮应具有相同的问题id名称,但值不同,即答案。
$all = mysql_query("SELECT * FROM 'questions'");
while($all_array=mysql_fetch_array($all))
{
$question = mysql_query("SELECT * FROM questions WHERE id='".$all_array['id']."'");
while($stat=mysql_fetch_array(question)){
echo $stat['question'] . '<br />';
echo '<input type="radio" name="' .$stat['id'].'" value="' . $stat['answer1'] . '" />' . $stat['answer1'] . '<br />';
echo '<input type="radio" name="' .$stat['id'].'" value="' . $stat['answer2'] . '" />' . $stat['answer2'] . '<br />';
echo '<input type="radio" name="' .$stat['id'].'" value="' . $stat['answer3'] . '" />' . $stat['answer3'] . '<br />';
echo '<input type="radio" name="' .$stat['id'].'" value="' . $stat['answer4'] . '" />' . $stat['answer4'] . '<br />';
}
}