Search the Community
Showing results for tags 'quiz'.
-
Hi, I have created a quiz and the questions get read from a MySql database table. I am now wanting to stop it repeating questions, when I first started this I thougt it would be easy just create a column called Duplicate and everytime a question got pulled I would mark it in the databse. So it would only read questions that had a "0" in the DuplicateCol and after reading the question it would put a "1" in place of the "0" That would work, the problem being multiple people are using it so if a 1 is there they wont all get asked the question. Anyway that idea is a fail now, which is a shame because everything else worked. Im hoping someone can show me another way on stopping duplicates. when I created the quiz I created a registration, and login page which have there own table I then created another table for the questions with multiple columns ie " id, Question, Answer1, Answer2, Answer3, CorrectAnswer, DuplicateCol " I had a number on my form which is a random number that lets say is "6" will then pull the question from column id 6 Query = "select Question,Answer1,Answer2,Answer3,CorrectAnswer,DuplicateCol from Questions where DuplicateCol= '0' AND id='" + RandomN.Text + "'" Anyway im for the time being lost until someone can give me ideas please, The registration, login table looks like this id, Serial, Email, UserName, Location, UserScore, Activated, I was thinking of adding q1, q2, q3, q4, q5, etc etc and then somehow if a question got pulled in my questions table with id "6" then put a "1" in the column but I think it might be to hard to try and cross reference 2 tables. Any Ideas ?
-
Need little help with the quiz problem. I want to set time limit for each question in quiz module (say 30 seconds) and after that time, the form will auto submit the question (auto submit = no option selected = unanswered). There are 3 questions, so total time limit is 90 sec (30 sec each). I'm doing this via XAMPP. The link below provide the work so far https://www.dropbox.com/s/4dzlgjtjzvs48vw/quiz.rar?dl=0 Thanks
-
Hi all, I want to make a quiz but I'm stock in the process. I've created a form with radiobuttons with questions, so for example: Question 1: Q1A,Q1B,Q1C Question 2: Q2A,Q2B,Q2C After visitors filled in the answers, the form post it to my results.php. This works perfectly. Now I have a MySQL database with: +----------+--------+-----+-----+-----+-----+-----+-----+ | PRODUCT | BRAND | Q1A | Q1B | Q1C | Q2A | Q2B | Q2C | +----------+--------+-----+-----+-----+-----+-----+-----+ | | | | | | | | | | product1 | Apple | 1 | 0 | 1 | 0 | 1 | 0 | | | | | | | | | | | product2 | HP | 0 | 1 | 1 | 1 | 1 | 1 | | | | | | | | | | | product3 | Dell | 0 | 0 | 0 | 0 | 1 | 0 | | | | | | | | | | | product4 | Compaq | 1 | 1 | 1 | 0 | 0 | 0 | +----------+--------+-----+-----+-----+-----+-----+-----+ So if the user select Q1C in question A and Q2A in question B, I want to count all the values from the selected columns, so in this case: Product1 = 1 + 0 = 1 Product2 = 1 + 1 = 2 Product3 = 0 + 0 = 0 Product4 = 1 + 0 = 1 Product 2 wins and is most relevant. I then want to show the top 3 on the page. In total I have about 20 questions and 400 products and I want to create a top 3 list, based on the selected answers. I have a few questions: 1) Is this possible? Or are there better ways to make a election/voting script? Any examples? 2) How can I add the values from multiple columns together and make a total score for the visitor? For example, I need something like this: http://www.stemwijzer.nl/votematch2k2006/app.html I really hope you guys can help me with this! I really want this!! Thanks so much in advance!! Kind regards, Mark
-
Hello guys! I need some help here. So this is the situation: I have a page where I teach other students. i want to create a quiz/exam for them. So there is a question and there is a box for answer. And I want that this form correct itself. So he/she click on the submit button and then there will be the results and if an answer is incorrect then there will be an explanation why is that incorrect and why is the good anser is correct. So I hope you guys understand and you can help me. Thank you!
-
Does anyone know how to do this? Use one multi- dimensional associative array to store the questions, choices and answers for this quiz. Use a nested foreach loop to display the questions and choices. Create and use a simple function to calculate the percentage based on the number correct out of the total number of questions.
-
Hi everyone, this is my first post here. I need some help with a PHP/MySQL multiple choice quiz that I'm making for a website. I have succesfully created a CMS to create new quizzes and then add questions and answers for it to a MySQL database table. I have written the code to loop through and display the questions and possible answers with radio buttons. I'm having trouble with the logic of correcting the quiz however. I've been searching online and trying different things for 2 days, but nothing I've come up across has helped me. I don't want to just download someone else's multiple choice quiz package, I want to be able to figure this out on my own (well, with your help!) because once I get the logic down, that's only half of what I need to do. No one else's pre-written package suits my needs. Well here goes. I have a CMS that creates a quiz and then adds questions and answers. The database table has the following fields: [id] [quizName] [question] [answerA] [answerB] [answerC] [answerD] [correctAnswer] On my quiz page, I have a dropdown box to select which quiz you want to take. Then I query the database looking for questions which have that quiz name. Here's my code: <form method="post" action="quizzes.php"> <?php $questionNumber = 1; $query = mysql_query("SELECT * FROM quizzes WHERE quizName = '$quizName'"); while ($result = mysql_fetch_array($query)) { ?> <p> <?php echo $questionNumber . ") " . $result['question'] . "<br>"; ?> <input type="radio" name="answer<?php echo $result['id'] ?>" value="A"> <?php echo $result['answerA']; ?> <br> <input type="radio" name="answer<?php echo $result['id'] ?>" value="B"> <?php echo $result['answerB']; ?> <br> <input type="radio" name="answer<?php echo $result['id'] ?>" value="C"> <?php echo $result['answerC']; ?> <br> <input type="radio" name="answer<?php echo $result['id'] ?>" value="D"> <?php echo $result['answerD']; ?> <br> </p> <?php $questionNumber +=1; } ?> <input type="submit" name="checkQuiz" value="Check Quiz"> </form> This displays the questions and answers nicely. I know I need some kind of unique identifier for each question as I'm displaying them all from a single while loop. Then when the submit button is clicked, I need to get the answer selected for each of the questions, and compare it to the correctAnswer field in the database for that question. Nothing I've tried has worked. Can anyone help me out. Even if you give me some pseudo code, I'll code it up myself and see if it works. If it doesn't, I'll paste it here to show you what I've done. Any help would be greatly appreciated! I spent about 20 hours on this to no avail and nothing I've found searching Google has helped me either.
-
Hey guys. As you can see from my post count i am new here and also new to php. I am trying to modify a code sample of a quiz system that uses mysql database to store all the info such as users,questions,answers,score etc. I have manage to modify the things i want but i am having a hard time making the questions appear in random order when the user takes the test. The table that sores the questions and the answers is named "mst_question" and it has the following structure: que_id | test_id | que_desc | ans1 | ans2 | ans4 | ans4 | true_ans I have tried two things: 1.Modified the query by adding the order by rand() function.I read it is not the fastest way but at this stage i don't care about speed. The results returned were indeed random but the score doesnt seem to work properly and sometimes i get the same question twice. More specific this the query i tried on my effort of eliminating duplicates but as i said it is not working properly: $rs=mysql_query("SELECT DISTINCT * FROM mst_question WHERE que_id IN (SELECT DISTINCT que_id FROM mst_question where test_id=$tid )",$cn) 2. I tried soring the results into an array and use the shuffle function but that didnt work either. I am guessing the query is correct and the reason it doesnt work properly has something to do with the way the results are being displayed but as i said i am a newbie to php/mySQL. This is the modified content of the php file. Any ideas/suggestions are welcome <?php session_start(); include("database.php"); extract($_POST); extract($_GET); extract($_SESSION); if(isset($subid) && isset($testid)) { $_SESSION[sid]=$subid; $_SESSION[tid]=$testid; header("location:quiz.php"); } if(!isset($_SESSION[sid]) || !isset($_SESSION[tid])) //An den exei tethei subject kai testid tous paei sto index.php { header("location: index.php"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Online Quiz</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="quiz.css" rel="stylesheet" type="text/css"> </head> <body> <?php include("header.php"); $rs=mysql_query("SELECT DISTINCT * FROM mst_question WHERE que_id IN (SELECT DISTINCT que_id FROM mst_question where test_id=$tid ) ORDER BY rand()",$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' && 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()); if($ans==$row[7]) { $_SESSION[trueans]=$_SESSION[trueans]+1; } echo "<h1 class=head1> Result</h1>"; $_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>"; mysql_query("insert into mst_result(login,test_id,test_date,score) values('$login',$tid,'".date("d/m/Y")."',$_SESSION[trueans])") or die(mysql_error()); echo "<h1 align=center><a href=review.php> Review Question</a> </h1>"; unset($_SESSION[qn]); unset($_SESSION[sid]); unset($_SESSION[tid]); unset($_SESSION[trueans]); exit; } } $rs=mysql_query("SELECT DISTINCT * FROM mst_question WHERE que_id IN (SELECT DISTINCT que_id 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>Some Error Occured</h1>"; session_destroy(); echo "Please <a href=index.php> Start Again</a>"; exit; } mysql_data_seek($rs,$_SESSION[qn]); $row= mysql_fetch_row($rs); echo "<form name=myfm method=post action=quiz.php>"; echo "<table width=100%> <tr> <td width=30> <td> <table border=0>"; $n=$_SESSION[qn]+1; echo "<tR><td><span class=style2>Que ". $n .": $row[2]</style>"; echo "<tr><td class=style8><input type=radio name=ans value=1>$row[3]"; echo "<tr><td class=style8> <input type=radio name=ans value=2>$row[4]"; echo "<tr><td class=style8><input type=radio name=ans value=3>$row[5]"; echo "<tr><td class=style8><input type=radio name=ans value=4>$row[6]"; if($_SESSION[qn]<mysql_num_rows($rs)-1) echo "<tr><td><input type=submit name=submit value='Next Question'></form>"; else echo "<tr><td><input type=submit name=submit value='Get Result'></form>"; echo "</table></table>"; ?> </body> </html>