我为 uni 做了一个小型在线测验,遇到了一个我已经解决的问题,但希望它与数据库一起工作,而不是我硬编码可能的答案,如果有人能提供帮助,那就太好了
<?php
session_start();
$id = $_GET['id'];
include('cdb.php');
$sql = "SELECT * FROM tblas where id='$id';";
$results = mysql_query($sql, $db);
$myrow = mysql_fetch_array($results);
if(isset($_POST['idc'])) {
$idc = $_POST['idc'];
} else {
$idc = 1;
}
$idc++;
if ($idc >=6)
{
$idc = "1";
}
if(isset($_POST['submit']))
{
$try = $_POST['answer'] ;
}
?>
<br>
<?php
if ($idc >1 && $idc <6)
{
echo "Question $id out of 4:<br />".$myrow['question'];
}
if($id > 0 && $id <5)
{
echo "<form name=\"form1\" method=\"post\" action = \"testttts.php?id=".$idc."\"/>";
echo "<select name=\"answer\">";
echo "<option value= \"0\">----------SELECT ONE----------</option>
<option value=\"1\">".$myrow['A']."</option>
<option value=\"2\">".$myrow['B']."</option>
<option value=\"3\">".$myrow['C']."</option>
<option value=\"4\">".$myrow['D']."</option>";
echo "<input type=\"hidden\" name=\"idc\" value=\"".$idc."\" />";
}
if($id >0 && $id <4)
{
echo "<input type=\"submit\" name=\"submit\" value=\"Continue\" />";
}
echo "</form>";
?>
<br><br>
<?php
If ($id == 4)
{
echo "<form name=\"form1\" method=\"post\" action = \"testttts.php?id=1\"/>";
echo "<input type=\"submit\" name=\"submit\" value=\"Finish\" />";
}
?>
<br><br>
<br><br>
<?php
if ($try == 5.55)
{
$_SESSION['tally'] ++;
} elseif ($try == 54.24)
{
$_SESSION['tally'] ++;
} elseif ($try == 6)
{
$_SESSION['tally'] ++;
} elseif ($try == 279.5)
{
$_SESSION['tally'] ++;
}
$tally=$_SESSION['tally'];
Echo "Test crap: <br>";
$try = $_REQUEST['answer'];
echo "$try <-- try";
$cor = $myrow['correct'];
echo "<br> $cor <-- correct";
echo "<br><br> tally --> $tally";
echo "<br> this is id: $id <br>";
$test=$_SESSION['test'];
$_SESSION['test'] ++ ;
Echo "session destroy $test <br>";
if ($id >=4)
{
session_destroy();
}
?>
<br><br><br><br><br>
我意识到它非常混乱,因为它是一项正在进行的工作,但如果有人能解释我将如何从数据库中获取数据以与选择的答案进行比较,那就太好了。
感谢任何可以提供任何帮助的人。
桌子长什么样
id|question | A | B | C | D | correct
1 | ????? | ??? | ???| ???| ???| 2
2 | ????? | ??? | ???| ???| ???| 1
3 | ????? | ??? | ???| ???| ???| 4
4 | ????? | ??? | ???| ???| ???| 4