473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

online quiz Minor Bugs

realin
254 100+
hi guys,

well my college is going to have tech fest tommorrow and i need to submit an online test module to them.. its my job for the day.. i need ur help as i am stuck in teh middle of no where and i dont have a mentor or something around me but you guys..

I have developed database and everything, the problem is.. how do i keep a track that no question is repeated .. I am picking the question in a way that..
Expand|Select|Wrap|Line Numbers
  1. select * from quiz order by rand() limit 1;
  2.  
each time it answers teh question.. the query is fired and question is then displayed.. but the questions are repeating most of teh time..

second thing i want to know is.. how do i store correct answers and wrong answers,.. is it a good idea to have session variables and increment them respectively as per the situation, or using database is a better option, i will have atleast 20 students sitting and giving a test at the time.. as no server is available so will have to use a PC which has just 512 MB ram.. so please suggest me..

And the last thing i want to know is, how do i put a timer inside the test thingy.. php cant give a clock or a countdown as javascript can.. but the issue is when the form is submitted the clock will also reset, as the browser will reload..

please help me in this .. all

thanks in advacne.. wating for the reply
Oct 28 '07 #1
5 1949
pbmods
5,821 Expert 4TB
Heya, Realin.

To solve the first problem, you'll need to keep track of which questions the User has answered.

You have two options; you can either store the data in a database, or if the Users don't have to log in, then it will probably be easier just to store the question IDs in a session variable.

For example:
Expand|Select|Wrap|Line Numbers
  1. $__sql = "
  2. SELECT
  3.         *
  4.     FROM
  5.         `quiz`
  6.     WHERE
  7.         `questionid`
  8.             NOT
  9.             IN
  10.             (
  11.                 '" . implode("',\n\t\t\t\t'", $_SESSION['questionsAnswered']) . "'
  12.             )
  13.     ORDER BY
  14.         RAND()
  15.     LIMIT 1";
  16.  
To create a timer, you can add a timeout variable to the session. At the start of the question page, add this:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['timeout'] = time() + 90; // 90-second timeout.
  2.  
And at the top of the page that processes the answer:
Expand|Select|Wrap|Line Numbers
  1. if( $_SESSION['timeout'] < time() )
  2. {
  3.     // Timer expired.
  4. }
  5.  
Oct 28 '07 #2
realin
254 100+
hiya pbmods,

you ma mann .. well thanks for the reply.. first query is why why we used \n and \t in implode.. and shall i store the ID numbers in the session variable as the concatenated string seperated by commas?

also i want to show the clock running down during the test... its 20 mins and 30 questions.. but if i use session variable then can javascript's function access it to show the countdown ?

also i gotta use the login thingy for users, then also i am planning to use session variable for the questions asked.. my requirement is that a single user shouldnt get the same question again, though the questions may be same for two or more users giving the test simultaneously
thanks once again.. sorry for dizzy post as i am typing on mobile
thnaks a lot
Oct 29 '07 #3
pbmods
5,821 Expert 4TB
Heya, Realin.

first query is why why we used \n and \t in implode.. and shall i store the ID numbers in the session variable as the concatenated string seperated by commas?
I added the "\n" and "\t"s so that the query looks nice when I look over my MySQL log file. They're not strictly necessary, but it does make your query more readable.

You'll want to store your questions as an array:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['questionsAnswered'] =
  2.     array
  3.     (
  4.         19    => 'A',
  5.         5    => 'C',
  6.         28    => 'A'
  7.     );
  8.  
and so on.

One change to the query: you'll want to use array_keys() if you do it this way:

Expand|Select|Wrap|Line Numbers
  1. $__sql = "
  2. .
  3. .
  4. .
  5.     WHERE
  6.         `questionid`
  7.             NOT
  8.             IN
  9.             (
  10.                 '" . implode("',\n\t\t\t\t'", array_keys($_SESSION['questionsAnswered'])) . "'
  11.             )
  12.  
also i want to show the clock running down during the test... its 20 mins and 30 questions.. but if i use session variable then can javascript's function access it to show the countdown ?
Set a JavaScript variable when the page loads:
Expand|Select|Wrap|Line Numbers
  1. echo '<script type="text/javascript"> // <![CDATA[
  2.     var countdown = new Number(', $_SESSION['timeout'] - time(), ');
  3. // ]]> </script>';
  4.  
$_SESSION['timeout'] - time() is equal to the number of seconds left until the session times out.
Oct 29 '07 #4
realin
254 100+
i am really sorry but i am unable to do the both.. can you just edit the things for me :(

plese i know i am noob and bad.,. but this is really urgent .. thanks
[PHP]
<?php session_start();
require_once("config.php");
$obj=new quiz();
if(!isset($key)){
$key="";
}
if(!isset($sname)){
$sname="";
}
if(!isset($read)){
$read=array('1000');

}



if(false==$obj->fetch_session_data($_GET['sid'])){
echo "Invalid Session, Please <a href='login.php' >Login Again</a>";
exit();
}
else{

if(!isset($sdata)){

$sdata=$obj->fetch_session_data($_GET['sid']);
$sname=$sdata[0]['user_name'];
$key=$sdata[0]['sess_id'];

}}

/****************User modifications********************/
$noq=5;

/******************SESSION Variable *************************/
if(!isset($_SESSION['ques']))
$_SESSION['ques']="0";
if(!isset($_SESSION['cor']))
$_SESSION['cor']="0";
if(!isset($_SESSION['wrong']))
$_SESSION['wrong']="0";
/****************ENDS in here *******************************/


if($_POST){
$val=$HTTP_POST_VARS;
$ans=$obj->get_row("lit_quiz","serial_no=$val[pop]");

if($ans['ans']==$val['quiz'])
$_SESSION['cor']+=1;
else
$_SESSION['wrong']+=1;

}

if($_SESSION['ques']>=$noq)
{

Echo "Total questions answered $_SESSION[ques]<br>
Right answers $_SESSION[cor]<br>
Wrong Answers $_SESSION[wrong]";
$sql="insert into quiz_result (part_name,cor_ans,wrn_ans) values('$sname',$_SESSION[cor],$_SESSION[wrong])";
@mysql_query($sql);
exit();
}


echo "<html>
<head>
<title>$title</title>
<script language='javascript' type='text/javascript' src='script.js'></script>
<link rel= 'stylesheet' type='text/css' href='style.css' />
<script language='javascript' type='text/javascript' src='script.js' ></script>
</head>";
echo "Welcome $sname<br>";


$sql="SELECT * FROM lit_quiz order by rand() limit 1";
print_r($_SESSION['qid']);
$_result=$obj->rQuery($sql);

echo "<div id='ques'>";
foreach($_result as $ques){

$_SESSION['ques']+=1;

echo "<form name='quiz_form' action='$_SERVER[PHP_SELF]?sid=$key' method='post'>
$_SESSION[ques].$ques[ques]<br>
<input type='hidden' name='pop' value='$ques[serial_no]' />
<input type='radio' name='quiz' value=1>&nbsp;$ques[opt1]<br>
<input type='radio' name='quiz' value=2>&nbsp;$ques[opt2]<br>
<input type='radio' name='quiz' value=3>&nbsp;$ques[opt3]<br>
<input type='radio' name='quiz' value=4>&nbsp;$ques[opt4]<br>
<input type='submit' value='Next>>' ><br></form>
";

}
echo "</div>";
echo "</html>";
?>[/PHP]
Oct 29 '07 #5
realin
254 100+
hey pbmods,

thanks a lot for the help, my application worked quite like a charm, i used cookies cause i couldnt store the array in to session variable, dont know how do we do it :P

heheheh.. also for the timer thingy i used javascript in the iframe, that is a pretty good solution... but i read somewhere iframes are not preferd, is it so ??


anyhow, you really helped me buddy.. thanks a lot

:) cheers !!
Oct 31 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sketcher | last post by:
Hi, I am trying to create a quiz, Code is as follows: <html> <head> <title>Quiz</title> </head> <BODY> <Center><TABLE cellSpacing=3 cellPadding=0 border=0>
5
by: Vandana Rola | last post by:
Hello Everyone, I am a beginner in Javascript.I want to create fun quiz tool using javascript (no database). The feature of that tool is every question has five choices. The user needs to select...
15
by: alanbe | last post by:
Greetings I am making a flashcard type application to help me in my TCP/IP protocols test. My instructor will test us periodically on how a device or networking function relates to the OSI...
4
by: DAL | last post by:
I want to build my kid a program that cycles through questions (using a label for the question), and lets him choose one of two radio buttons for the right answer. How do I get every set of...
0
by: josh | last post by:
Hi, I'm new to ASP.NET. I need to develop a quiz application in ASP.NET/C#. The requirements are: 1. Questions are read from an XML file (or a database, but right now i'm reluctant about that)...
2
by: kenny | last post by:
I'm making a quiz to be posted on the internet. but I'm facing difficulties in finding a simple timer for the quiz (unlimited timing) which will keep on running regardless to the change of the page...
0
by: techjohnny | last post by:
Hello Group, I'm searching for an opensource php quiz that allows for multiple answers. Instead of using radio button, I'd like to use check boxes. Thanks, --TJ
3
by: empiresolutions | last post by:
I am building a app that creates quizzes. This is how it goes - - Create Quiz - Provide up to 10 different types of Quiz Results - Give up to 50 Questions - Each Question has up to 10 possible...
25
by: doznot | last post by:
Let's say you want to use Moodle to teach an introductory class in PHP programming. Some of the students have little or no computer experience. In addition to background reading and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.