Sie sind auf Seite 1von 4

<html>

<head>
<title>Mental Ability Quiz</title>
<style type="text/css">
.navbar
{
overflow: hidden;
background-color: #3d3d77; /* color change for band 1 */
position: fixed; /* Set the navbar to fixed position */
top: 0; /* Position the navbar at the top of the page */
width: 100%; /* Full width */
height: 50px;
}
body
{
margin: 0;
padding-top: 55px;
background-color: lightblue; /* color change for entire page */ /*
Downlaod ColorZilla extension from Chrome webstore */
color: red; /* Font color */
}

#quiz-time-left
{
font-size: 20px;
text-align: right;
padding-right: 30px;
padding-top: 10px;
}

form
{
font-size: 20px;
background: white;
margin-left: 10%;
margin-right: 10%;
padding-right: 10px;
padding-left: 10px;
padding-top: 10px;
padding-bottom: 10px;
border-radius: 18px;
box-shadow: 5px 5px 10px #707070;
}
</style>
<script type="text/javascript">
alert(1);
var CheckedAnswer[] = "";

function storeA(i)
{
//var i = <?php echo $i; ?>;
CheckedAnswer[i] = "A";

}
function storeB(i)
{
//var i = <?php echo $i; ?>;
CheckedAnswer[i] = "B";
}
function storeC(i)
{
//var i = <?php echo $i; ?>;
CheckedAnswer[i] = "C";

}
function storeD(i)
{
//var i = <?php echo $i; ?>;
CheckedAnswer[i] = "D";

}
function Calculate()
{
for(var x=1; x<11; x++)
{
"The Submitted answer is" +CheckedAnswer[x];
}
document.getElementById("demo").innerHTML = text;
}
</script>
</head>
<body>
<?php
$host="localhost";
$dbUsername="id6193565_himanshu9xm";
$dbPassword="iwbo4/1/99";
$dbname="id6193565_registered";
$conn = mysqli_connect($host, $dbUsername, $dbPassword, $dbname); //new
connection

if(! $conn )
{
die('Connect Error('. mysqli_connect_errno().')'.
mysqli_connect_error());
}

$sql = 'SELECT id, questions, optiona, optionb, optionc, optiond,


answer FROM MentalAbilityQuestions Order by rand() limit 10;';
mysqli_select_db($conn,"id6193565_registered");
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
die('Could not get data:( '.mysqli_errno().')' . mysqli_error());
}

?>
<div class="navbar">
<div id="quiz-time-left"></div>
</div>
<form action="Calculate();">
<?php
$i = 1;
$totalScore = 0;
$correctanswer[] = "";

while($row = mysqli_fetch_array($retval, MYSQLI_BOTH))


{
echo '<fieldset>';
echo '<legend>Question ';
echo $i;
echo '</legend>';
echo '<p>';
echo "{$row['questions']}";
echo '</p>';
echo '<p><label><input type="radio" name="answer' .
$row['id'] . '" onclick="storeA('.$i.');" value="A">';
echo "{$row['optiona']}";
echo '</label></p>';
echo '<p><label><input type="radio" name="answer' .
$row['id'] . '" onclick="storeB('.$i.');" value="B">';
echo "{$row['optionb']}";
echo '</label></p>';
echo '<p><label><input type="radio" name="answer' .
$row['id'] . '" onclick="storeC('.$i.');" value="C">';
echo "{$row['optionc']}";
echo '</label></p>';
echo '<p><label><input type="radio" name="answer' .
$row['id'] . '" onclick="storeD('.$i.');" value="D">';
echo "{$row['optiond']}";
echo '</label></p>';
echo '</fieldset>';
//to store correct answers inorder to compare for
calculating score STEP-1:
$correctanswer[$i] = $row['answer'];
$i++;

}
echo '<br><br>';
echo '<button style="height: 30px; width: 80px; font-size:
1em; box-shadow: 5px 5px 10px #707070;border-radius: 15px; margin-left: 50%;"
onclick="Calculate();">Submit</button>';
echo '<p id="demo"></p>';
echo '<br>';
?>
</form>
<br><br>

<script type="text/javascript">

var total_seconds=5*60;
var c_minutes = parseInt(total_seconds/60);
var c_seconds = parseInt(total_seconds%60);

function CheckTime(){
document.getElementById("quiz-time-left").innerHTML
= 'Time Left: ' + c_minutes + ' minutes ' + c_seconds + ' seconds ' ;

if(total_seconds <=0)
{
setTimeout('document.quiz.submit()',1);
}
else
{
total_seconds = total_seconds -1;
c_minutes = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",1000);
}
}
setTimeout("CheckTime()",1000);

</script>
</body>
</html>