testing app.
Posted: Wed Aug 22, 2007 7:34 pm
Hello, I am developing a app for school which you can create a practice test and use the Test ID to access your test, and I need help displaying the actually testing part. I want it so that the script pics a random question (one that hasn't been used before, and makes you answer that question (no refreshing to change the question) if your right it counts it correct, same for wrong. Whats below is what I have so far. All I need help with at this point is making the question "stay" the current question... any critiquing would be awsome!
Note: this isn't for actually testing, just for practice test so it doesn't have to be "cheat proof", but that would be nice
Note: this isn't for actually testing, just for practice test so it doesn't have to be "cheat proof", but that would be nice
Code: Select all
<?php
ob_start();
@require("db.php"); //database settings... i'm using @ because i'm lazy and dont want any error print outs.
session_name('eTests');
session_start();
if(!isset($_GET['testID']) && !is_numeric($_GET['testID']) && !isset($_POST['testID']) && !is_numeric($_POST['testID'])){
header("Location: index.php");
exit();
} else {
if(!isset($_SESSION['questionUsed'])){
$_SESSION['questionUsed'] = array();
}
$testID = $_GET['testID'];
$getTestInfo = mysql_query("SELECT * FROM `tests` WHERE `testID` =".$testID." LIMIT 1");
$getTestInfoArray = mysql_fetch_array($getTestInfo);
$testName = $getTestInfoArray['testName'];
$getQuestions = mysql_query("SELECT * FROM `questions` WHERE `testID` =".$testID."");
while($row = mysql_fetch_array($getQuestions)){
$questions[$row[0]] = $row;
$questionsAll[] = $row[0];
}
$qCount = count($questions);
if(isset($_POST['questionID']) && !empty($_POST['questionID'])){
if(!in_array($questionID,$_SESSION['questionUsed'])){
$_SESSION['questionUsed'][] = $questionID;
}
}
foreach($questionsAll as $cQ){
if(!in_array($cQ,$_SESSION['questionUsed'])){
$questionToUse[] = $cQ;
}
}
if(count($questionToUse)!=0){
foreach($questions as $thisQ){
if(in_array($thisQ[0],$questionToUse)){
$questionList[] = $thisQ;
}
}
srand((float)microtime() * 1000000);
shuffle($questionList);
$theQuestion = $questionList[0];
$currentQuestion = $theQuestion['testQuestion'];
$currentQuestionID = $theQuestion['questionID'];
print_r($theQuestion);
} else {
$completed = true;
unset($_SESSION['questionUsed']);
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $testName; ?></title>
<style type="text/css">
<!--
.Title {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 24px;
font-weight: bold;
}
-->
</style></head>
<body>
<div align="center"><span class="Title"><?php echo $testName; ?></span></div>
<p> </p>
<form id="question" name="question" method="post" action="?testID=<?php echo $testID; ?>">
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><strong>
<input name="questionID" type="hidden" id="questionID" value="<?php echo $currentQuestionID; ?>" />
<input name="testID" type="hidden" id="testID" value="<?php echo $testID; ?>" />
<?php if($completed==false){ ?> Q: <?php echo $currentQuestion; ?><?php } else { echo '<center>You have completed the test.</center>'; }?></strong></td>
</tr>
<tr>
<td><?php
if($currentQuestion){
?>
<label for="textfield"><strong>A: </strong></label>
<input name="answer" type="text" id="answer" size="50" maxlength="255" />
<?php
}
?> </td>
</tr>
<tr>
<td align="center" valign="middle" style="padding-top:10px;"><label for="Submit"></label>
<input type="submit" name="Submit" value="Submit" id="Submit" /></td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
<?php } ?>