CREATETABLEIFNOTEXISTS`questions`(`id`int(11)NOTNULLAUTO_INCREMENT,`question_name` text NOTNULL,`answer1`varchar(250)NOTNULL,`answer2`varchar(250)NOTNULL,`answer3`varchar(250)NOTNULL,`answer4`varchar(250)NOTNULL,`answer`varchar(250)NOTNULL,`category_id`int(11)NOTNULL,PRIMARYKEY(`id`))ENGINE=InnoDB DEFAULTCHARSET=latin1 AUTO_INCREMENT=21;
INSERTINTO`questions`(`id`,`question_name`,`answer1`,`answer2`,`answer3`,`answer4`,`answer`,`category_id`)VALUES(1,'Where did India play its 1st one day international match?','Lords','Headingley','Taunton','The Oval','2',1),(2,'Who was the 1st ODI captain for India?\r\n','Ajit Wadekar ','Bishen Singh Bedi','Nawab Pataudi','Vinoo Mankad ','1',1),(3,'Who has made the Fastest Test century in Test Cricket ?\r\n\r\n\r\n\r\n','Sachin Tendulkar',' Sahid Afridi',' Virender Sehwag','Vivian Richards','4',1),(4,'Which Bowler had the Best figures in a Test Match ?\r\n\r\n\r\n\r\n\r\n','Muttiah Muralitharan','Bob Massie','Jim Laker','George Lohmann','3',1),(5,'Which team has the Largest successful run chase record in ODIs ?\r\n\r\n\r\n\r\n\r\n','England','South Africa','Australia','India','2',1),(6,'What does HTML stand for?\r\n\r\n \r\n \r\n ','Hyper Text Markup Language','Hyperlinks and Text Markup Language','Home Tool Markup Language','Highly Text Markup Language','1',2),(7,'Who is making the Web standards?\r\n\r\n \r\n \r\n \r\n \r\n','Microsoft','Google','The World Wide Web Consortium','Mozilla','3',2),(8,'What is the correct HTML for creating a hyperlink?\r\n\r\n \r\n \r\n \r\n ','<a name="http://smarttutorials.net">Smart Tutorials</a>','<a>http://smarttutorials.net</a>','<a url="http://smarttutorials.net">Smart Tutorials</a>','<a href="http://smarttutorials.net">Smart Tutorials</a>','4',2),(9,'What is the HTML element to bold a text?\r\n\r\n\r\n\r\n\r\n','<b>','<bold>','<wide>','<big>','1',2),(10,'What is the HTML tag for a link?\r\n\r\n\r\n\r\n\r\n','<link>','<ref>','<a>','<hper>','3',2),(11,'What does CSS stand for?\r\n\r\n \r\n \r\n \r\n ','Creative Style Sheets','Colorful Style Sheets','Computer Style Sheets','Cascading Style Sheets','4',4),(12,'Where in an HTML document is the correct place to refer to an external style sheet?\r\n\r\n \r\n \r\n \r\n ','In the <body> section ','At the end of the document','At the top of the document','In the <head> section ','4',4),(13,'Which HTML tag is used to define an internal style sheet?\r\n\r\n \r\n \r\n ','<script>','<css>','<style>','<link>','3',4),(14,'Which is the correct CSS syntax?\r\n\r\n \r\n \r\n \r\n ','body:color=black;','{body;color:black;}','body {color: black;}','{body:color=black;}','3',4),(15,'Which property is used to change the background color?\r\n\r\n \r\n \r\n ','background-color','color','bgcolor','bg-color','1',4),(16,'What does PHP stand for?\r\n\r\n \r\n \r\n ',' PHP: Hypertext Preprocessor','Personal Hypertext Processor','Personal Home Page','Private Home Page','1',3),(17,'PHP server scripts are surrounded by delimiters, which?\r\n\r\n \r\n \r\n \r\n ','<?php>...</?>','<?php ... ?>','<script>...</script>','<&>...</&>','2',3),(18,'How do you write "Hello World" in PHP\r\n\r\n \r\n \r\n ','"Hello World"','echo "Hello World"','Document.Write("Hello World");','print_f("Hello World");','2',3),(19,' Which of the following is the way to create comments in PHP?\r\n\r\n\r\n \r\n \r\n ','// commented code to end of line','/* commented code here */','# commented code to end of line','all of the above - correct','4',3),(20,'What is the correct way to end a PHP statement?\r\n\r\n \r\n \r\n \r\n ','</php>','.',';','New line','3',3);
Here is the sample database relational daigram of above three tables.
Step 2:
Create config.php file to keep database connection in a separte file. Also kept two utilities database related functions to prepare prepared statements and get results.
Now create question.php and add following scripts. This is main file of this quiz application which gets questions randomily from database for each the user. As well it take care previous and next button functionality using jQuery.
Step 8:
Finally create app.js file, then keep the user validation logic during user registration & Quiz questions pagination logic (previous & next button logic).
$(document).ready(function(){if($("#signin").validate){$("#signin").validate({
submitHandler:function(form){
form.submit();},
rules :{
name :{
required :true,
minlength :3,
remote :{
url :"check_name.php",
type :"post",
data :{
username :function(){return$("#name").val();}}}},
category:{
required :true}},
messages :{
name :{
required :"Please enter your name",
remote :function(){$('#name').rules('remove','remote');return"";return"Name is already taken, Please choose some other name"}},
category:{
required :"Please choose your category to start Quiz"}},
errorPlacement :function(error, element){$(element).closest('.form-group').find('.help-block').html(error.html());},
highlight :function(element){$(element).closest('.form-group').removeClass('has-success').addClass('has-error');},
success :function(element, lab){var messages =newArray("That's Great!","Looks good!","You got it!","Great Job!","Smart!","That's it!");var num = Math.floor(Math.random()*6);$(lab).closest('.form-group').find('.help-block').text(messages[num]);$(lab).addClass('valid').closest('.form-group').removeClass('has-error').addClass('has-success');}});}});$('.cont').addClass('hide');
count =$('.questions').length;$('#question'+1).removeClass('hide');$(document).on('click','.next',function(){
last=parseInt($(this).attr('id'));
nex = last+1;$('#question'+last).addClass('hide');$('#question'+nex).removeClass('hide');});$(document).on('click','.previous',function(){
last=parseInt($(this).attr('id'));
pre = last-1;$('#question'+last).addClass('hide');$('#question'+pre).removeClass('hide');});
If you want any of my script need to be customized according to your business requirement,
Please feel free to contact me [at] muni2explore[at]gmail.com
Note: But it will be charged based on your customization requirement
Get Updates, Scripts & Other Useful Resources to your Email
Join 10,000+ Happy Subscribers on feedburner. (We don't send spam) Every Email Subsciber could have access to download 100+ demo scripts & all future scripts.