我正在尝试检查用户选择的答案是否正确,但它不能正常工作:
<form method="post">
<?php
$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="a'.$x.'" value="'.$x.'" />' .$stat['answer1']."<br />";
echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer2'] . '<br />';
echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer3'] . '<br />';
echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer4'] . '<br />';
$questionid++;
$x = $x+1;
}
echo $result;
?>
<input type="submit" name="go" value="Go" />
</form>
那部分基本上是:
$x = 1;
$question = mysql_query("SELECT * FROM `questions`");
$stat = mysql_fetch_assoc($question);
$num = mysql_num_rows($question);
if(isset($_POST['go']))
{
for($i=0;$i<$num;$i++)
{
if ($_POST['ans'.$x] == $row['correct'])
{
$result = $result + 1;
}
$x = $x + 1;
}
}
出于某种原因,它没有正确发布结果,我认为代码有问题,希望得到帮助。