嘿伙计们我正在尝试进行一项针对uni的5个问题的在线测验,并且我只想弄清楚我将如何使用sql和php进行计数,目前我有一个想法但它似乎没有以我期待的方式工作。这是为了请求一个答案,如果它与sql列匹配,它会向$ _SESSION ['tally']添加一个点,虽然目前无论答案是什么,它仍然会增加1来计算...任何帮助将是伟大的家伙< / p>
<?php
session_start();
if(!isset($_SESSION['idc']))
{
$_SESSION['idc'] = 1;
}
$count = $_SESSION['idc'];
$_SESSION['idc'] ++ ;
if ($_SESSION['idc'] >= 6)
{
session_destroy();
}
$id = $_GET['id'];
include('cdb.php');
echo "<br><br>";
$sql = "SELECT * FROM tblas where id='$id';";
$results = mysql_query($sql, $db);
$myrow = mysql_fetch_array($results);
$id2 = "$id=1";
if ($_REQUEST['answer1'] === $myrow['correct'])
{
$_SESSION['tally'] ++ ;
}
?>
<br><br><br>
<?php
if ($count >1 && $count <7)
{
echo 'Question: '.$myrow['question'];
}
echo $myrow['A'];
?>
<form name="form2" method="post">
<select name="answer1">
<option value=$myrow['A']><?php echo $myrow['A']?></option>
<option value=$myrow['B']><?php echo $myrow['B']?></option>
<option value=$myrow['C']><?php echo $myrow['C']?></option>
<option value=$myrow['D']><?php echo $myrow['D']?></option>
<input type="submit" name="submit" value="Continue" onclick = "window.location.href = 'testttts.php?id=<?php echo $count?>'"
</form>
<br><br>
<br><br>
<br><br>
<?php
$idc = $_SESSION['idc'];
$tally = $_SESSION['tally'];
echo "this is $ _ session tally: $tally";
Echo "<br> this is ID count: $idc";
?>
这应该是所有相关的代码,任何问题或任何有助于此的问题,我会尽力帮助你帮助我!
感谢任何对此提供帮助的人。
对不起它通常很麻烦它只是我看着它直到它完成。