<?phpsession_start();include ("database.php");extract ($_POST);extract ($_GET);extract($_SESSION);/*$rs=mysql_query("select * from mst_question where test_id=$tid",$cn) or die(mysql_error());if($_SESSION[qn]>mysql_num_rows($rs)){unset($_SESSION[qn]);exit;}*/if(isset($subid) && isset($testid)){$_SESSION[sid]=$subid;$_SESSION[tid]=$testid;header("location:quiz.php");}if(!isset($_SESSION[sid]) || !isset($_SESSION[tid])){ header("location: index.php");}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[url=http://www.w3.org/TR/html4/loose.dtd]http://www.w3.org/TR/html4/loose.dtd[/url]"><html><head><title>Online Quiz</title> <meta charset="utf-8" /><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link href="quiz.css" rel="stylesheet" type="text/css"></head><body bgcolor="#236"> <table hieght="250" align="center" class="paperTable" height="500"><tr> <td> <span class="style4"> <?php///include("header.php");/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////$rs=mysql_query("select * from mst_question where test_id=$tid",$cn) or die(mysql_error());if(!isset($_SESSION[qn])){ $_SESSION[qn]=0; mysql_query("delete from mst_useranswer where sess_id='" . session_id() ."'") or die(mysql_error()); $_SESSION[trueans]=0; }else /////if($submit=='Next Question' && ans==""){////////// echo $msg="Please Select any answer";////// }///////// else{ ////////////////////////////////////////////////////THIS IS FOR RESULT.... if($submit=='Next Question' && isset($ans)) { mysql_data_seek($rs,$_SESSION[qn]); $row= mysql_fetch_row($rs); mysql_query("insert into mst_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error()); if($ans==$row[7]) { $_SESSION[trueans]=$_SESSION[trueans]+1; } $_SESSION[qn]=$_SESSION[qn]+1; } else if($submit=='Get Result' && isset($ans)) { mysql_data_seek($rs,$_SESSION[qn]); $row=mysql_fetch_row($rs); mysql_query("insert into mst_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error()); // include("result1.php"); // echo "<h1 align=center><a href=result1.php> Result</a> </h1>"; if($ans==$row[7]) { $_SESSION[trueans]=$_SESSION[trueans]+1; } echo "<h1 class=head1> Result</h1>"; echo "<hr />"; echo "<br />"; echo "Click on review link to view all the correct answers"; $_SESSION[qn]=$_SESSION[qn]+1; echo "<Table align=center><tr class=tot><td>Total Question :<td> $_SESSION[qn]"; echo "<tr class=tans><td>True Answer :<td>".$_SESSION[trueans]; $w=$_SESSION[qn]-$_SESSION[trueans]; echo "<tr class=fans><td>Wrong Answer :<td> ".( $w); echo "</table>"; echo "<br />"; $percentage=floor(($_SESSION[trueans]*100)/$_SESSION[qn]) ; echo "You Scored : " .$percentage." %"; echo "<br />"; if($percentage>=70){ echo "Congratulations! you passed the exam."; } else{ echo "<br />"; echo "<span class=fans>Sorry! you are failed.</span>"; } mysql_query("insert into mst_result(login,test_id,test_date,score) values('$login',$tid,'$date',$_SESSION[trueans])") or die(mysql_error()); echo "<h1 align=center><a href=review.php>>>>>> Review Question<<<<<<</a> </h1>"; echo "To pass this exam you'll have to score at least 70%."; unset($_SESSION[qn]); unset($_SESSION[sid]); unset($_SESSION[tid]); unset($_SESSION[trueans]); exit; echo "<br />"; }}//////////////////////////////////////////////////////////////////////////if there are no quesitons....OR the exam paper is not ready yet...$rs=mysql_query("select * from mst_question where test_id=$tid",$cn) or die(mysql_error());if($_SESSION[qn]>mysql_num_rows($rs)-1){//unset($_SESSION[qn]);echo "<h1 class=head1>This Exam Paper is not ready yet.<br />Please Contact the Administrator OR the Incharge of Examination.</h1>";//session_destroy();echo "Please <a href=sublist.php> Start Again</a>";exit;}//////////////////////////////////////////////////////////////////////////This is the paper area...Through which someone take the exam....mysql_data_seek($rs,$_SESSION[qn]);$row= mysql_fetch_row($rs);include("timer2.php");////////Timer is included here.........echo "<br />";echo "<br />";echo "<hr />";echo "<form name=myfm method=post action=quiz.php>";echo "NOTE : Select one RadioButton located at the front of each question";echo "<table width=100%><table align=center> <tr> <td width=30> <td> <table border=1 cellpad=2 cellspace=2>";$n=$_SESSION[qn]+1;echo "<tR><td ><span class=head1>Que ". $n .": $row[2]</style>";echo "<tr><td height=30 class=style8>$row[3]</td><td><input type=radio name=ans value=1></td>";echo "<tr><td height=30 class=style8>$row[4]</td><td><input type=radio name=ans value=2></td>";echo "<tr><td height=30 class=style8 >$row[5]</td><td><input type=radio name=ans value=3></td>";echo "<tr><td height=30 class=style8>$row[6]</td><td><input type=radio name=ans value=4></td>";if($_SESSION[qn]<mysql_num_rows($rs)-1)echo "<tr><td height=30><input type=submit name=submit value='Next Question' ></form>";elseecho "<tr><td><input type=submit name=submit value='Get Result'></form>";echo "</table></table>"; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////?> </span></td></tr></table></body></html> Now the above coding is correct ...it shows the proper result.....when someone does the paper within the time....So everything is just fine with this.... But how to do coding for when the time is upExample: there are 100 questions..and you did only 80 due to the shortage of time...and in 80 questions there will be some true answers and some false answers...So the result should be like this...total questions:100attempted: 80true:whatever e.g 55false:whatever e.g 25percentage...55%