Responsive Quiz Application Using PHP, MySQL, jQuery, Ajax and Twitter Bootstrap Part-3

Posted by & filed under Ajax, JQUERY, MYSQL, PHP.

In this tutorial I made few changes in the Responsive Quiz Application Using PHP, MySQL, jQuery, Ajax and Twitter Bootstrap based on the request from users.

Note : You can refer my latest Quiz application
 
Responsive PHP Quiz Script

Before continuing this tutorial please refer my previous tutorials on this Responsive Quiz Application Using PHP, MySQL, jQuery, Ajax and Twitter Bootstrap.

1.  Responsive Quiz Application Using PHP, MySQL, jQuery, Ajax and Twitter Bootstrap

2. Responsive Quiz Application Using PHP, MySQL, jQuery, Ajax and Twitter Bootstrap Part-2

Now user can able select number of questions to be showed on each pages.

 

 

Responsive Quiz Application Using PHP, MySQL, jQuery, Ajax and Twitter Bootstrap - 3

Responsive Quiz Application Using PHP, MySQL, jQuery, Ajax and Twitter Bootstrap – 3

Step 1:

$number_question = $_POST['num_questions'];
$row = mysqli_query( $con, "select * from questions where category_id=$category ORDER BY RAND()");
$rowcount = mysqli_num_rows( $row );
$remainder = $rowcount/$number_question;

where

$number_question — set number of questions to be showed on each pages.

I am selecting quiz questions from particular category that the user choosed, then finding number questions in the result of mysqli_query() finally stored questions count in  $rowcount variable. Finally finding the remainder by dividing $rowcount  with $number_question (number of question to be showed on each page.)

 

 

Step 2:

<?php while ( $result = mysqli_fetch_assoc($row) ) {
						 if ( $i == 0) echo "<div class='cont' id='question_splitter_$j'>";?>
						<div id='question<?php echo $k;?>' >
						<p class='questions' id="qname<?php echo $j;?>"> <?php echo $k?>.<?php echo $result['question_name'];?></p>
						<input type="radio" value="1" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/><?php echo $result['answer1'];?>
						<br/>
						<input type="radio" value="2" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/><?php echo $result['answer2'];?>
						<br/>
						<input type="radio" value="3" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/><?php echo $result['answer3'];?>
						<br/>
						<input type="radio" value="4" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/><?php echo $result['answer4'];?>
						<br/>
						<input type="radio" checked='checked' style='display:none' value="5" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/>                                                                      
						<br/>
						</div>
						<?php
							 $i++; 
							 if ( ( $remainder < 1 ) || ( $i == $number_question && $remainder == 1 ) ) {
							 	echo "<button id='".$j."' class='next btn btn-success' type='submit'>Finish</button>";
							 	echo "</div>";
							 }  elseif ( $rowcount > $number_question  ) {
							 	if ( $j == 1 && $i == $number_question ) {
									echo "<button id='".$j."' class='next btn btn-success' type='button'>Next</button>";
									echo "</div>";
									$i = 0;
									$j++;           
								} elseif ( $k == $rowcount ) { 
									echo " <button id='".$j."' class='previous btn btn-success' type='button'>Previous</button>
												<button id='".$j."' class='next btn btn-success' type='submit'>Finish</button>";
									echo "</div>";
									$i = 0;
									$j++;
								} elseif ( $j > 1 && $i == $number_question ) {
									echo "<button id='".$j."' class='previous btn btn-success' type='button'>Previous</button>
							                    <button id='".$j."' class='next btn btn-success' type='button' >Next</button>";
									echo "</div>";
									$i = 0;
									$j++;
								}

							 }
							  $k++;
					     } ?>

For example if I am going to show two questions on each page, if user choose category that contains only one question then I need to show that one question with finish button to complete quiz.

If $remainder<1 that means number  questions less than number questions to be showed on each page, so I need to complete quiz with finish button.

if ( ( $remainder < 1 ) || ( $i == $number_question && $remainder == 1 ) ) {
	echo "<button id='".$j."' class='next btn btn-success' type='submit'>Finish</button>";
	echo "</div>";
 }

if number questions goes greater than number questions to be showed on each page then following logic will come into play.

elseif ( $rowcount > $number_question  ) {
  if ( $j == 1 && $i == $number_question ) {
    echo "<button id='".$j."' class='next btn btn-success' type='button'>Next</button>";
    echo "</div>";
    $i = 0;
    $j++;           
  } elseif ( $k == $rowcount ) { 
    echo " <button id='".$j."' class='previous btn btn-success' type='button'>Previous</button>
		<button id='".$j."' class='next btn btn-success' type='submit'>Finish</button>";
    echo "</div>";
    $i = 0;
    $j++;
  } elseif ( $j > 1 && $i == $number_question ) {
     echo "<button id='".$j."' class='previous btn btn-success' type='button'>Previous</button>
		 <button id='".$j."' class='next btn btn-success' type='button' >Next</button>";
     echo "</div>";
     $i = 0;
     $j++;
}

Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts

If you want any of my script need to be customized according to your business requirement,

Please feel free to contact me [at] muni[at]smarttutorials.net

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. Click to Subscribe (We don't send spam)
Every Email Subsciber could have access to download 100+ demo scripts & all future scripts.

  • Joe Koder

    Glad to see you updated the code to Mysqli. One problem you might want to address: Every time a user reloads the page the quiz/timer resets.

  • muni

    Thank you foy your valuable comment Joe..

    Many Thanks,

    muni

  • swang

    You did an amazing tutorial Muni ! you save my day many thanks guy

  • Vitor Sousa

    i i subscribded, but i still cant download de files…

    Is any problem with that?

    So you catched my e-mail adress and…

    Thank you

  • Vitor Sousa

    Hi i got the files that i want, but when user wants to repeat the quiz it takes him to index and if he wants to repeat several times he needs to enter his name.. and i dont know how to fix it…

    Anyone can help?

    thanks

  • http://www.smarttutorials.net/ muni

    Hi Victor,

    If user enters his/her name first time those value saved in session, once he finished quiz then he want take quiz all need to do is just press start a quiz button it brings him to index page, where he only he need to choose category quiz he had choosen… No need to re-enter his name again.

    Many Thanks,

    muni

  • Jihed

    How can I set the counter to each question?

  • Keerthi

    i want random questions each time when i refresh :( i want that source code :(

  • http://dreamlib.vn Quocuy

    Please create some sub categories for each category. For example, first, user can choose class 6,7,8,9. Next user can choose courses: math, history, english. In math, user can choose chapter 1,2,3… Thank you!

  • Yogesh Ojha

    Hello, Can you please send me the download link?

  • muni

    sent

  • Rodrigo

    This example applies to jQuery Mobile? I signed my email but not received the source code of this project .. Could it available?

  • Chetan

    Hi, Muni. You did an amazing tutorial.

    Can I get the download Link for this one?

  • pravin

    nice work just let me know how to show correct / incorrect response message for all questions

  • A v Klinken

    Can i please get the download link? I just subscribed :)

  • Wattburg

    Hey Muni,

    I just subscribed, so can you send me the download link? :)

  • Mech Clavano

    good morning sir! your tutorials are great. I subscribed already to get the source code but i didn’t receive. can you give me the source code??? this is the best quiz game i’m looking for. Im a student and part of our project is to make a quiz game. please help me.

    Thank you! :)

  • David Blomstrom

    I just subscribed and would like to request the source code as well. Nice quiz software!

  • muni

    pls check your mail, i had sent download link…..

  • Okulaja Ganiu

    Hello sir! your tutorials are great. I just subscribe to get the download too.
    this is the best quiz i have been looking for. Though, i need something that will be displaying the questions (one by one) I’m a student and one of my project is to make a quiz game. please help sir

  • arvind malav

    great one..need this for my php project….can you plz send me download link for this 3rd part?

  • arvind malav

    I just subscribed to get the download too. but did not get any link…can u email me this link to arvindmalav1@gmail.com

  • Guest

    Thanks for sending the link

    However,…it does not include database tables…

    Can u plz send database tables structure as well?

  • Guest

    got it on first post..thanks

  • http://smarttutorials.net/ muni

    Hi Okulaja,

    pls set $number_question = 1 instead of $number_question = $_POST[‘num_questions’]; this will display the queations one by one.

    Also check my latest quiz tutorial .

    http://www.smarttutorials.net/php-quiz-application-using-jquery-ajax-mysql-bootstrap/

  • Madalin

    Hello muni! This script is amazing but how can i add multiple answers instead single answer possibility?

  • Lizel Atis

    Can you please send me the script as well as the database. It would be a great help in my project ..

  • Saad Khanzada

    Subscribed to feed plz send me download link s.khanzada@mail.com. I didn’t received download link.
    Thanks

  • Vinti Thukral

    kindly send me the download link at vinti.thukral@gmail.com i have subscibed…

  • devi priya

    hello sir, very easy tutorial , i subscribed too can u send me download link to may mail id sir.. devipriya0693@gmail.com

  • Mahmoud

    Can you send me the download link please at m.sliman10@yahoo.com

  • http://mmaonline.info Marcelo

    Muni, how to select only 20 random questions at the database over 20 questions for the same subject ?

  • Alba Marquinos

    I subscribe already kindly send script to marquinosalba@gmail.com

Get Instant Script Download Access!

jfate.net skinporngalls.biz tubevaporn tellyporn thatpornpage sistie youvideoporno heresyourporn chuley dzsexy onlinepornteens