Hey guys,

The problem: I have a 3 question quiz which obtains the questions and answer options from a database. At the moment, I've managed to display all 3 questions on one page under one form.

What I'm trying to do: Display one question per page.

I've tried to google for help but only found one solution which is to use cookies, are there any other options?

I've included a snippet of my code here.

Thanks in advance for any help.

$query1 = "SELECT hWord, OPT_1, OPT_2, OPT_3, OPT_4, ANS FROM easyTab ORDER BY Rand() LIMIT 1";
			$result1 = mysql_query($query1, $conn) or die(mysql_error());
		
			while ($row = mysql_fetch_array($result1, MYSQL_NUM))
				{
					?>
					<form name="quizgame1" method="post" action="checkquiztest.php?">			

					<ul class = "form">
					<li>
				
					Choose the closest meaning of this word:<br> <?php echo $row[0]; ?> <br><br>
						
						<input type="radio" name="ans1" value="<?php echo $row[1]?>" title="<?php echo $row[1];?>"  <br><br>
						<input type="radio" name="ans1" value="<?php echo $row[2]?>" title="<?php echo $row[2];?>" /> <br><br>
						<input type="radio" name="ans1" value="<?php echo $row[3]?>" title="<?php echo $row[3];?>"  /> <br><br>
						<input type="radio" name="ans1" value="<?php echo $row[4]?>" title="<?php echo $row[4];?>"  <br>
						
						<input type="hidden" name="correctanswer1" value="<?php echo $row[5]?>" />
					</li>
						</ul>
						
						<?
				}
				
					
			$query2 = "SELECT hWord, OPT_1, OPT_2, OPT_3, OPT_4, ANS FROM easyTab ORDER BY Rand() LIMIT 1";
			$result2 = mysql_query($query2, $conn) or die(mysql_error());
		
			while ($row = mysql_fetch_array($result2, MYSQL_NUM))
				{
					?>
					<form name="quizgame1" method="post" action="checkquiztest.php?">			

					<ul class = "form">							
					
					<li>
				
					Choose the closest meaning of this word:<br> <?php echo $row[0]; ?> <br><br>
						
						<input type="radio" name="ans2" value="<?php echo $row[1]?>" title="<?php echo $row[1];?>"  <br><br>
						<input type="radio" name="ans2" value="<?php echo $row[2]?>" title="<?php echo $row[2];?>" /> <br><br>
						<input type="radio" name="ans2" value="<?php echo $row[3]?>" title="<?php echo $row[3];?>"  /> <br><br>
						<input type="radio" name="ans2" value="<?php echo $row[4]?>" title="<?php echo $row[4];?>"  /> <br>
						
						<input type="hidden" name="correctanswer2" value="<?php echo $row[5]?>" />
					</li>
						</ul>
						
						<?
				}
			
			$query3 = "SELECT hWord, OPT_1, OPT_2, OPT_3, OPT_4, ANS FROM easyTab ORDER BY Rand() LIMIT 1";
			$result3 = mysql_query($query3, $conn) or die(mysql_error());
		
			while ($row = mysql_fetch_array($result3, MYSQL_NUM))
				{
					?>
					<form name="quizgame1" method="post" action="checkquiztest.php?">			

					<ul class = "form">							
					
					<li>
				
					Choose the closest meaning of this word:<br> <?php echo $row[0]; ?> <br><br>
						
						<input type="radio" name="ans3" value="<?php echo $row[1]?>" title="<?php echo $row[1];?>"  />  <br><br>
						<input type="radio" name="ans3" value="<?php echo $row[2]?>" title="<?php echo $row[2];?>"  /> <br><br>
						<input type="radio" name="ans3" value="<?php echo $row[3]?>" title="<?php echo $row[3];?>" /> <br><br>
						<input type="radio" name="ans3" value="<?php echo $row[4]?>" title="<?php echo $row[4];?>"  /> <br>
						
						<input type="hidden" name="correctanswer3" value="<?php echo $row[5]?>" />
					</li>
						</ul>
						
						<?
				}
					?>
					
						
		
		
		<p><center><input id="submitans" name="submitans" type ="submit" class="button white" value = "Submit"></center></p>
Member Avatar for TechySafi

Eww! Your code is not aligned properly really hard to read. :)
Why you are using three different form and 3 queries if you want to show just one question per page?

Actually what you want to do? Whats inside quizgame1.php ? If you would explain that I might find a way for you.

dear why you are using one page i can tell u that when u will create 3 pages then i will guide u how to setle them.
create 3 pages and show question from 3 tables on every pages and update each pages after that data will be saved in table user_ans then u can sum the user answer on result page when 3 pages ended.

I've managed to sort it out.

I split the questions into 3 separate pages and used sessions to store the answer chosen by the user. This allowed me to call and display the answers on the results page :)

Thanks for your comments and suggestions though!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.