从数据库得分以进行测验

时间:2013-10-16 11:39:59

标签: php mysql session

我已经为uni做了一个小小的在线测验,并且已经遇到了一个我已经过来的问题,但是希望它能够与数据库一起工作,而不是我硬编码可能的答案,如果有人可以提供帮助那么会很好< / p>

 <?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

0 个答案:

没有答案