Hello,
I am making a quiz script for a website I am doing and I am having a bit of trouble on the javascript part of the script. All the information in the page below is pulled from a mysql datbase with php. What i am trying to do is when you hit start it goes through all the generated divs one by one by the designated time which is changable via the admin panel. The problems I'm having with the script im using is:
the script doesnt seem to be following the time limit for all questions
the script has a long pause in the begining.
the script does not stop when finished displaying all results
Any help would be appreciated, if you know of another method i could use then please let me know. Thanks
script in action:
Code:
http://dlgresults.com/dev/wm/quiz.inc.php
code:
Code:
<script language="JavaScript" type="text/JavaScript">
<!--
var defaultTimeOut = 15000; //Default timeout 15 seconds
//Starts the rotation.
function startRotation (howMany, timeOut) {
defaultTimeOut = timeOut;
setTimeout('rotateLayers(' + howMany + ')', defaultTimeOut);
}
// This function rotates the visibility of layers randomly.
function rotateLayers (howMany) {
for (var i=1; i<=howMany; i++) eval("document.all.rotatingLayer" + i +
".style.visibility = 'hidden'");
eval("document.all.rotatingLayer" + (Math.round(Math.random() * (howMany
- 1)) + 1) + ".style.visibility = 'visible'");
setTimeout('rotateLayers(' + howMany + ')', defaultTimeOut);
}
//-->
</script>
<style type="text/css">
.questionflick {layer-background-color: #FFFFCC; border: 1px none #000000; visibility:
hidden; position:absolute; }
</style>
<?
require('includes/config.php');
require('core/database.php');
$database = new database();
$database->connect();
switch ($function) {
default:
$query = $database->query("SELECT * FROM quiz");
while ($list = mysql_fetch_array($query)) {
$id = stripslashes($list['id']);
$name = stripslashes($list['name']);
$description = stripslashes($list['description']);
$names22 .= '
<div><a href="?function=start&quid='.$id.'">'.$name.'</a> • '.$description.'</div>
';
$row_count++;
}
echo '<h2>Select a quiz below to start</h2>
'.$names22.'';
break;
case "start" :
$quid = $_GET['quid'];
$query = $database->query("SELECT * FROM quiz where id = $quid");
while ($list = mysql_fetch_array($query)) {
$id = stripslashes($list['id']);
$name = stripslashes($list['name']);
$description = stripslashes($list['description']);
$howlong = stripslashes($list['howlong']);
}
$i = '1';
$query = $database->query("SELECT * FROM quiz_quest WHERE main = $quid ORDER by id ");
while ($list = mysql_fetch_array($query)) {
$qid = stripslashes($list['id']);
$qquestion = stripslashes($list['question']);
$qmain = stripslashes($list['main']);
$qquestions .= '
<div id="rotatingLayer'.$i++.'" class="questionflick">'.$qquestion.'</div>
';
}
$howmany = mysql_num_rows($query);
?>
<input name="start" type="button" id="start" value="Click here to start <?php echo $name;?>!"
onClick="startRotation(<?php echo $howmany;?>, <?php echo $howlong;?>);"/>
<?
$howlong = $howlong / 1000;
echo '<h1>'.$howmany.' Questions, you have '.$howlong.' seconds per question</h1>';
echo '<h2>'.$qquestions.'</h2>';
break;
}
?>
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions
Please login or register to view this content. Registration is FREE
Great hosting at affordable pricing!
|