...

View Full Version : online quiz query



swati soni
09-15-2009, 01:53 PM
I am at the first stage of creating a quiz.
I wish to know is it possible to click a button to proceed to the next question, with questions to be asked using for/while loop

I want to use

1. php as scripting language.
2. Mysql as database.
3. For each correct answer there should be increment of 1 in score.
4. all questions are multiple choice questions.

I have writen a code but its not working properly,which is given below
If u can suggest something it would be a great help

Thanks in advance


code which i have written is:-



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
//$password=""; // Mysql password
$db_name="rounds"; // Database name
$tbl_name="round1"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT id,question,a,b,c,d,ans FROM $tbl_name";
$res=mysql_query($sql);
$count=mysql_num_rows($res);
//for($i=0;$i<$count;$i++)
$i=0;
$score=0;

do{

echo " ".mysql_result($res,$i,0);
echo " ".mysql_result($res,$i,1).'<br/>';

?>
<form method="get" >
<p>
<label>
<input type="radio" name="RadioGroup1" value="<?php echo " ".mysql_result($res,$i,2);?>" />
<?php echo " ".mysql_result($res,$i,2);?></label>
<br>
<label>
<input type="radio" name="RadioGroup1" value="radio" />
<?php echo " ".mysql_result($res,$i,3);?></label>
<br>
<label>
<input type="radio" name="RadioGroup1" value="radio" />
<?php echo " ".mysql_result($res,$i,4);?></label>
<br>
<label>
<input type="radio" name="RadioGroup1" value="radio" />
<?php echo " ".mysql_result($res,$i,5);?></label>
<br>
<?php
if (isset($_POST['RadioGroup1'])) {
$selected_radio = $_POST['RadioGroup1'];
print $selected_radio;
if($selected_radio==mysql_result($res,$i,6))
{
$score++;
}
}
$i=$i+1;
?>
</p>

</form>
<br>
<?php
}while($i<$count);
?>


<form id="form1" name="form1" method="post" >
<label>
<input type="submit" name="Submit" value="Finish" />

</label>
<?php
echo "$score";
?>
</form>

</body>
</html>

Fumigator
09-15-2009, 03:28 PM
Read this:

http://codingforums.com/showthread.php?t=68462



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum