Код:
function showNextQ()
{
qCount = qCount + 1;
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Ваш браузер не поддерживает аякс");
return;
}
[B]if(document.forms.answers) {
if (document.getElementById('itog').value == 1)
{
AllPoints = seconds+AllPoints;
}
}[/B]
var url="load.php";
url=url+"?qcount="+qCount+"&points="+seconds+"&answer="+answer+"&allpoints="+AllPoints;
if(document.forms.answers) url=url+"&question="+document.getElementById('question').value;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
document.getElementById("topLiders").innerHTML='';
seconds = 21;
}
load.php
if($_GET["question"] && $_GET["answer"])
{
$query="select otvet from vika where num=".$_GET["question"];
$result=mysql_query($query);
if (mysql_result($result, 0) == $_GET["answer"])
{
echo "Правильно<br />";
echo "Балл за вопрос:".$_GET["points"];
$allpoints=$allpoints+$_GET["points"];
$itog=1;
echo "<br />";
echo "<div id='balls'>Всего баллов:".$allpoints."</div><br />";
}
else
{
$otvno+=1;
echo "Неправильно!<br />";
$allpoints=$allpoints;
echo "Баллы:".$_GET["points"]."<br />";
echo "Всего баллов:".$allpoints;
echo "<br />";
$itog=0;
}
}
if ($_GET['qcount'] <= 5)
{
$id=rand(1,3672);
$query="select * from vika where num=".$id;
$result=mysql_query($query);
if ($result)
{
while($row=mysql_fetch_object($result))
{
echo 'Вы отвечаете на <b>'.$_GET['qcount'].'</b> вопрос';
echo "<p><div><b>".$row->vopros."</b></div></p>";
echo '<form name="answers">';
echo '<input type="radio" id="answer_id" name="answer" value="1" checked>'.$row->otvet1.'</input><br />';
echo '<input type="radio" id="answer_id" name="answer" value="2">'.$row->otvet2.'</input><br />';
echo '<input type="radio" id="answer_id" name="answer" value="3">'.$row->otvet3.'</input><br />';
echo '<input type="radio" id="answer_id" name="answer" value="4">'.$row->otvet4.'</input><br />';
echo $itog;
echo '<input type="button" value="Следующий" onClick="whatChecked(); showNextQ(); ">';
echo '<input type="hidden" value='.$id.' name="question" id="question">';
echo '<input type="hidden" value='.$itog.' name="itog" id="itog">';
echo '</form>';
}