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.. -
select * from quiz order by rand() limit 1;
-
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
5 1949
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: -
$__sql = "
-
SELECT
-
*
-
FROM
-
`quiz`
-
WHERE
-
`questionid`
-
NOT
-
IN
-
(
-
'" . implode("',\n\t\t\t\t'", $_SESSION['questionsAnswered']) . "'
-
)
-
ORDER BY
-
RAND()
-
LIMIT 1";
-
To create a timer, you can add a timeout variable to the session. At the start of the question page, add this: -
$_SESSION['timeout'] = time() + 90; // 90-second timeout.
-
And at the top of the page that processes the answer: -
if( $_SESSION['timeout'] < time() )
-
{
-
// Timer expired.
-
}
-
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
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: -
$_SESSION['questionsAnswered'] =
-
array
-
(
-
19 => 'A',
-
5 => 'C',
-
28 => 'A'
-
);
-
and so on.
One change to the query: you'll want to use array_keys() if you do it this way: -
$__sql = "
-
.
-
.
-
.
-
WHERE
-
`questionid`
-
NOT
-
IN
-
(
-
'" . implode("',\n\t\t\t\t'", array_keys($_SESSION['questionsAnswered'])) . "'
-
)
-
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: -
echo '<script type="text/javascript"> // <![CDATA[
-
var countdown = new Number(', $_SESSION['timeout'] - time(), ');
-
// ]]> </script>';
-
$_SESSION['timeout'] - time() is equal to the number of seconds left until the session times out.
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> $ques[opt1]<br>
<input type='radio' name='quiz' value=2> $ques[opt2]<br>
<input type='radio' name='quiz' value=3> $ques[opt3]<br>
<input type='radio' name='quiz' value=4> $ques[opt4]<br>
<input type='submit' value='Next>>' ><br></form>
";
}
echo "</div>";
echo "</html>";
?>[/PHP]
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 !!
Sign in to post your reply or Sign up for a free account.
Similar topics
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>
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |