我正在使用 MYSQL 进行测验现在我想要执行以下功能
1--> 我的数据库中有 250 个问题,但我想在 50 个问题后停止查询。(一次选择一个)
2-->我想在单击该按钮后添加按钮检查正确答案,用户可以在他的答案下看到“正确”和“错误”。
请帮帮我
我的测验提问代码
<html>
<title>Quiz</title>
<body bgcolor="#666666"> </body>
<h1><center> Quiz </center></h1>
<?php
echo "Welcome Student";
echo " ";
echo "<a href=logout.php>Logout</a>";
?>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$dataselect = mysql_select_db("quiz",$con);
if(!$dataselect)
{
die("Database namelist not selected".mysql_error());
}
?>
$query = "SELECT * FROM question ORDER BY RAND() LIMIT 0,1";
$result = mysql_query($query) or die("Error processing query. ".mysql_error());
echo "<form method = 'post' action = 'submit.php'>";
echo "<table border = '1'>";
while($data = mysql_fetch_array($result))
{
echo "".$data['Question']."<br>";
echo "<input type = 'radio' name='radio' value='Option1'>";
echo "".$data['Option1']."<br>";
echo "<input type = 'radio' name='radio' value='Option2'>";
echo "".$data['Option2']."<br>";
echo "<input type = 'radio' name='radio' value='Option3'>";
echo "".$data['Option3']."<br>";
}
echo "<tr><td align = 'center'><input type = 'submit' name = 'go' value = 'GO'></td></tr>";
echo "</table>";
echo "</form>";
在上面的代码中,用户一次被问一个问题,从 DB 中随机选择,然后这个代码将他的答案存储到 DB
<?php
$connection = mysql_pconnect("localhost", "root", "") or die ("Error connection. ".mysql_error());
mysql_select_db("quiz", $connection) or die("Error selecting db. ".mysql_error());
$Option['Option1'] = false;
$Option['Option2'] = false;
$Option['Option3'] = false;
$Option[$_POST['radio']] = true;
$order= "INSERT INTO radio (Option1,Option2,Option3) VALUES ('".$Option['Option1']."','".$Option['Option2']."','".$Option['Option3']."')";
$result=mysql_query($order) or die(mysql_error());
?>
<html>
<title>Answer Submission</title>
<body bgcolor="#666666"></body>
<center><b><h2>Your Answer Has Been Submitted Successfully Please Click On NEXT To Move Towards Next Question"</h2><br>
<br>
<br>
<button onClick="window.location.href='Quiz.php'"><center><h3>NEXT</h3></center></button>
<center><b><h2>Your Answer Has Been Submitted Successfully Please Click On Result To Get Your Results Till Yet"</h2><br>
<button onClick="window.location.href='studresult.html'"><center><h3>NEXT</h3></center></button>
</html>
但我不知道如何限制它在 50 个问题后停止的查询:/