hello everyone..i just wanna ask how i can increment the score after each answer given by the user and at last displaying result after questions finish. i want to store the result in database
here's my code which is working fine with checking questions and displaying result and then next question. moveover i want following things
1) to increment score after every correct answer
2) to store the final score in database with these foreign id's (course_id, evaluation_id, student_id)
3) to display final result and passing percentage after the last answer display
4) to check how much perentage is set for passing i have a column named pass percentage in evaluations table, which teacher have already fixed while making the quiz.
here's my code
start-course-evaluation.php
<?php include("../includes/config.php"); ?>
<?php
if ($_SESSION["isstudent"])
{
$cid= $_GET['id'];
$eid=$_GET['eid'];
$qid=$_GET['qid'];
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$result1 = mysql_query("SELECT learningmaterial.id,learningmaterial.title,evaluation.id AS eid, evaluation.learningmaterialid FROM learningmaterial JOIN evaluation ON learningmaterial.id=evaluation.learningmaterialid");
while($row = mysql_fetch_array($result1))
{
$name=$row['title'];
$evaluationid=$row['eid'];
}
?>
<?php
$result = mysql_query("SELECT * FROM courses WHERE (id=".$cid.")");
while($row = mysql_fetch_array($result))
{
$title=$row['title'];
}
?>
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>
<!--[if lt IE 9]>
<script type="text/javascript" src="js/excanvas/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="js/spinners/spinners.min.js"></script>
<script type="text/javascript" src="js/lightview/lightview.js"></script>
<link rel="stylesheet" type="text/css" href="css/lightview/lightview.css"/>
<?php include("../includes/pre-header.php");?>
<title>Evaluation</title>
</head>
<body>
<div class="container">
<?php include("../includes/header.php"); ?>
<?php include("includes/nav.php"); ?>
<div id="maincontent">
<div class="span-24 last">
<div id="breadcrumbs" class="mycss">
<a href="index.php">Home</a> >
<a href="my-courses.php">My Courses</a> >
<a href="start-course.php"><?php echo $title; ?></a> >
<a href="start-course-evaluation.php"><?php echo $name; ?></a> >
Start Course
</div>
</div>
<?php include("includes/offered-courses-aside.php"); ?>
<br /> <br />
<div class="span-18 last">
<h2 class="alt"><?php echo $title ?></h2>
<?php
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $con);
if (isset($_GET["qid"])){
$query = "SELECT * FROM questions WHERE (evaluationid=".$eid.") AND id > ".$qid." ORDER BY id ASC LIMIT 1";
$result = mysql_query($query);
{
echo "<form action='display-answer.php' method='post'>";
$num_rows = mysql_num_rows($result);
if ($num_rows > 0)
{
$row = mysql_fetch_array($result);
$qid=$row['id'];
$question=$row['question'];
$right_answer=$row['answer'];
echo " <strong>" . $row['question'] . "</strong><br /><br /><br />";
if ($row['type'] === 'MCQs')
{
echo "<input type='radio' value='possible_opt_1' name='user-answer' checked />";
echo $row['possible_opt_1']; echo "<br />";
echo "<input type='radio' value='possible_opt_2' name='user-answer' />";
echo $row['possible_opt_2'];echo "<br />";
echo "<input type='radio' value='possible_opt_3' name='user-answer' />";
echo $row['possible_opt_3'];echo "<br />";
echo "<input type='radio' value='possible_opt_4' name='user-answer' />";
echo $row['possible_opt_4'];echo "<br /><br /><br />";
}
else {
echo "<input type='radio' value='possible_opt_1' name='user-answer' />";
echo $row['possible_opt_1']; echo "<br />";
echo "<input type='radio' value='possible_opt_2' name='user-answer' />";
echo $row['possible_opt_2'];echo "<br />";
}
echo "<input type='hidden' name='id' value='".$cid."' />";
echo "<input type='hidden' name='eid' value='".$eid."' />";
echo "<input type='hidden' name='qid' value='".$qid."' />";
echo "<input type='hidden' name='question' value='".$question."' />";
echo "<input type='hidden' name='right_answer' value='".$right_answer."' />";
echo "<input type='hidden' name='right_answer' value='".$right_answer."' />";
echo "<input type='submit' name='next' value='next' />";
}
echo "</form>";
}
}
else
{
$query="SELECT * FROM questions WHERE (evaluationid=".$eid.")";
$result = mysql_query($query);
echo "<form action='display-answer.php' method='post'>";
$num_rows = mysql_num_rows($result);
if ($num_rows > 0)
{
$row = mysql_fetch_array($result);
$qid=$row['id'];
$question=$row['question'];
$right_answer=$row['answer'];
echo " <strong>" . $row['question'] . "</strong><br /><br /><br />";
if ($row['type'] === 'MCQs')
{
echo "<input type='radio' value='possible_opt_1' name='user-answer' checked />";
echo $row['possible_opt_1']; echo "<br />";
echo "<input type='radio' value='possible_opt_2' name='user-answer' />";
echo $row['possible_opt_2'];echo "<br />";
echo "<input type='radio' value='possible_opt_3' name='user-answer' />";
echo $row['possible_opt_3'];echo "<br />";
echo "<input type='radio' value='possible_opt_4' name='user-answer' />";
echo $row['possible_opt_4'];echo "<br /><br /><br />";
}
else {
echo "<input type='radio' value='possible_opt_1' name='user-answer' />";
echo $row['possible_opt_1']; echo "<br />";
echo "<input type='radio' value='possible_opt_2' name='user-answer' />";
echo $row['possible_opt_2'];echo "<br />";
}
echo "<input type='hidden' name='eid' value='".$eid."' />";
echo "<input type='hidden' name='qid' value='".$qid."' />";
echo "<input type='hidden' name='question' value='".$question."' />";
echo "<input type='hidden' name='right_answer' value='".$right_answer."' />";
echo "<input type='hidden' name='id' value='".$cid."' />";
echo "<input type='submit' name='next' value='next' />";
}
echo "</form>";
}
mysql_close($con);
?>
<?php
/*
$correct = 0;
if(isset($_POST['answer'])) {
$selected_opt=$_POST['answer'];
if ($selected_opt== $row['answer'])
{
$correct+= 10;
echo "your answer is right";
}
else
{
echo "your answer is wrong";
}
}
*/
?>
</div>
</div>
<?php include("../includes/footer.php"); ?>
</div>
</body>
</html>
<?php
}
else
{
header("Location: ".$fullpath."login/unauthorized.php");
}
?>
display-answer.php
<?php include("../includes/config.php"); ?>
<?php
if ($_SESSION["isstudent"])
{
?>
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>
<!--[if lt IE 9]>
<script type="text/javascript" src="js/excanvas/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="js/spinners/spinners.min.js"></script>
<script type="text/javascript" src="js/lightview/lightview.js"></script>
<link rel="stylesheet" type="text/css" href="css/lightview/lightview.css"/>
<?php include("../includes/pre-header.php");?>
<title>Evaluation</title>
</head>
<body>
<div class="container">
<?php include("../includes/header.php"); ?>
<?php include("includes/nav.php"); ?>
<div id="maincontent">
<div class="span-24 last">
</div>
<?php include("includes/aside.php"); ?>
<div class="span-18 last">
<h1 class="alt">Result</h1>
<?php
$eid=$_POST['eid'];
$qid=$_POST['qid'];
$question=$_POST['question'];
$right_answer=$_POST['right_answer'];
$user_answer=$_POST['user-answer'];
$cid=$_POST['id'];
if ($right_answer==$user_answer)
{
$score+=10;
echo "<h1 class='mycss'>Your answer is right</h1>"; echo "<br />";
echo "<h3 class='mycss' >your current score is '".$score."' </h3>";echo "<br />";
$score ++;
}
else
{
echo "<h2 class='mycss'>Your answer is wrong </h2>"; echo "<br />";
echo "<h2 class='mycss'>The right answer is '".$right_answer."'</h2>"; echo "<br />";
echo "<h1 class='mycss'>your current score is '".$score."'</h1>"; echo "<br />";
}
?>
<form method="get" action="start-course-evaluation.php">
<input type="hidden" name="qid" value="<?php echo $qid; ?>" />
<input type="hidden" name="id" value="<?php echo $cid; ?>" />
<input type="hidden" name="eid" value="<?php echo $eid; ?>" />
<input type="submit" class="mybutton" name="next" value="next" />
</form>
</div>
</div>
<?php include("../includes/footer.php"); ?>
</div>
</body>
</html>
<?php
}
else
{
header("Location: ".$fullpath."login/unauthorized.php");
}
?>
any kind of help would be appreciated :)