can someone help.
its a little quiz script. it loads first question but wont load second question after you click.
its a little quiz script. it loads first question but wont load second question after you click.
Code:
<?php
include("config.php");
$sql_q = "SELECT * FROM questions"; $res_q = mysql_query($sql_q); $nr_questions = mysql_num_rows($res_q);
?>
<html>
<head>
<title><?=$TITLE?></title>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
var points = 0, nr_questions = <?=$nr_questions?>;
var answers = new Array();
<?php
$sqlr = "SELECT * FROM results ORDER BY points ASC"; $resr = mysql_query($sqlr); $i = 0;
while ($rowr = mysql_fetch_array($resr)) {
echo "answers[$i] = new Array(2);";
echo "answers[$i][0] = '".$rowr['points']."';";
echo "answers[$i][1] = '".$rowr['result']."';\n";
$i++;
}
?>
function add_points(nr,nrpoints) {
points = points + nrpoints;
document.getElementById("question"+nr).style.display="none";
try {
document.getElementById("question"+(nr+1)).style.display="inline";
} catch(err) {}
if (nr == nr_questions) {
document.location="result.php?result=" + points;
/*var i = 0;
while (points > answers[i][0])
i++;
alert("Total points: " + points + "\n" + answers[i][1]);*/
}
}
</script>
</head>
<body>
<table width="100%" border="0">
</table>
<table width="100%" border="0">
<tr>
</tr>
<tr>
<td><div align="center"><?php
$i = 1;
while ($rowq = mysql_fetch_array($res_q)) {
echo "<div id='question".$i."'";
if ($i != 1) echo ' style="display:none;" ';
echo "><h1>".$rowq['question']."</h1>";
$sql_a = "SELECT * FROM answers WHERE question=".$rowq['id']; $res_a = mysql_query($sql_a);
while ($rowa = mysql_fetch_array($res_a)) {
echo "<b><h2><a href='javascript:void(0);' onclick='add_points(".$i.",".$rowa['points'].");'>".$rowa['answer']."</a><br /></h2></b?";
}
echo '</div>'; $i++;
}
?>
</div>
</table>
</body>
</html>