我遇到这样的问题, 我有一个有很多问题的数据库库和他们加入的答案'多选系统'! 我写了一个PHP脚本,每次用户进入页面时检索(15)问题,'index.php'作为单选按钮。
现在我的贝斯要我改变显示问题的方法!所以,而不是在同一页面上的15个问题!他要求每次出示一个问题,如下:
================================================================================
1. Question TEXT:
a. 1st variant
b. 2nd variant
c. 3rd variant
d. 4th variant
<NEXT QUESTION>
================================================================================
所以通过点击“提交”按钮,脚本应该将我重定向到文件的第二部分,该部分必须显示第二个问题,从第二部分如上所示到第三个 - &gt;四 - &gt; ... - &gt;第15个问题
================================================================================
1st question is: Correct //This part will check the correction/incorrection of the previous question -_-
2. Question2 TEXT:
a. 1st variant
b. 2nd variant
c. 3rd variant
d. 4th variant
<NEXT QUESTION>
================================================================================
底线,我能够在页面上带15个问题,在检查答案后,我给出了结果。但我可以弄清楚如何将这些问题分发到各个页面!如
'index.php?question=1'
'index.php?question=2'
'index.php?question=3'
...
'index.php?question=15'
谢谢你们!
答案 0 :(得分:1)
正如我所说,我想将从一个查询中检索到的结果分发到各个页面中,我想出了这个想法, 1.做了相同的查询
SELECT * FROM database ORDER BY RAND() LIMIT 10
然后我将检索到的问题的IDz保存到数组中,就像那样
$id = array();
$_SESSION[corr] = 0;
$_SESSION[incorr] = 0;
while ($row = mysql_fetch_assoc($query) {
$id[] = $row[ID];
}
然后我将数组保存到SESSION中,以便在每个所需的页面中传递它,如下所示
$_SESSION[ID] = $id;
之后我设置了一个链接,如
echo "<a href=test.php?question=1>Click To Start</a>";
最后但并非最不重要的是做了类似的事情
if ($_REQUEST['question'] == '1') {
$id = $_SESSION['id'];
$sql = mysql_query("SELECT * FROM `test` WHERE `id` = '$id[0]'") or die("Error" .mysql_error());
$row = mysql_fetch_assoc($sql);
echo "<font color=green>Correct: " .$_SESSION[corr]. "</font></br>";
echo "<font color=red>Incorrect: " .$_SESSION[incorr]. "</font></br>";
echo "$row[v]<br>";
echo "<form action='test.php?question=2' method='POST'>";
echo "<input type=radio name=answer1 value=1>$row[o1]</input><br>";
echo "<input type=radio name=answer1 value=2>$row[o2]</input><br>";
echo "<input type=radio name=answer1 value=3>$row[o3]</input><br>";
echo "<input type=radio name=answer1 value=4>$row[o4]</input><br>";
echo "<input type=submit name=submit value=Check>";
echo "</form>";
$_SESSION['previous_id'] = $row['id'];
exit;
并在下一部分&#34; test.php?question = 2&#34; 我首先检查上一个问题是否正确解答如下
if ($_REQUEST['question'] == '2') {
$id = $_SESSION['id'];
$answer = $_POST['answer1'];
$grade = mysql_query("SELECT * FROM `test` WHERE `id` = {$_SESSION['previous_id']}") or die();
$right = mysql_fetch_assoc($grade);
if ($answer == $right[g]) {
$_SESSION['corr']++;
echo "<font color=green>Correct</font></br>";
}
else {
$_SESSION['incorr']++;
echo "<font color=red>Incorrect, check lesson #".$right[lvl]."</font></br>";
}
$sql = mysql_query("SELECT * FROM `test` WHERE `id` = '$id[1]'") or die("Error" .mysql_error());
$row = mysql_fetch_assoc($sql);
echo "$row[v]<br>";
echo "<form action='test.php?question=3' method='POST'>";
echo "<input type=radio name=answer2 value=1>$row[o1]</input><br>";
echo "<input type=radio name=answer2 value=2>$row[o2]</input><br>";
echo "<input type=radio name=answer2 value=3>$row[o3]</input><br>";
echo "<input type=radio name=answer2 value=4>$row[o4]</input><br>";
echo "<input type=submit name=submit value=Check>";
echo "</form>";
$_SESSION['previous_id'] = $row['id'];
exit;
}
这只是我想要的100%,但它只是感觉不专业,因为我不得不重写代码,或者复制和编辑上面显示的相同代码很多次,考虑到我试图发布10或15问题分开..
希望这有助于其他人!