quiz -sammentælning?
Hej.Jeg er igang med at lave en quiz, som kan ses her:
http://www.musikviden.dk/test/undersider/quiz.php
- Jeg bruger php og en mysql-database.
I databasne har jeg de rigtige svar liggende, men jeg aner ikke hvordan jeg skal sætte den til at tælle dem op! ... jeg skal jo skrive hvor mange rigtige svar brugeren havde...
Her er lidt kode:
--------------------------------------------------------
</TR>
<?php
$db=mysql_connect("********","********","********");
mysql_select_db("musikvidendk",$db);
$foresp = mysql_query("SELECT id, q1, q2, q3, q4, q5, 1svar1, 1svar2, 1svar3, 2svar1, 2svar2, 2svar3, 3svar1, 3svar2, 3svar3, 4svar1, 4svar2, 4svar3, 5svar1, 5svar2, 5svar3 FROM quiz order by id desc limit 0,1");
while($data=mysql_fetch_array($foresp)){
?>
</table><BR><BR>
<table border="0" width="340" height="26" cellpadding="0" cellspacing="0">
<TR>
<td colspan="2"><font face="verdana" size="1"><B>1. <? echo $data[1]; ?></B></font></td>
</TR>
<TR>
<td width="20" height="20">
<form action="quiz.php" method="post">
<input type="radio" name="quest1" value="nr1">
</td>
<td width="320" height="20"><font face="verdana" size="1">a. <? echo $data[6]; ?></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest1" value="nr2">
</td>
<td width="320" height="20"><font face="verdana" size="1">b. <? echo $data[7]; ?></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest1" value="nr3">
</td>
<td width="320" height="20"><font face="verdana" size="1">c. <? echo $data[8]; ?></font></td>
</TR>
<TR>
<td height="20" colspan="2"></td>
</tr>
<TR>
<td colspan="2"><font face="verdana" size="1"><B>2. <? echo $data[2]; ?></B></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest2" value="nr1">
</td>
<td width="320" height="20"><font face="verdana" size="1">a. <? echo $data[9]; ?></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest2" value="nr2">
</td>
<td width="320" height="20"><font face="verdana" size="1">b. <? echo $data[10]; ?></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest2" value="nr3">
</td>
<td width="320" height="20"><font face="verdana" size="1">c. <? echo $data[11]; ?></font></td>
</TR>
<TR>
<td height="20" colspan="2"></td>
</tr>
<TR>
<td colspan="2"><font face="verdana" size="1"><B>3. <? echo $data[3]; ?></B></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest3" value="nr1">
</td>
<td width="320" height="20"><font face="verdana" size="1">a. <? echo $data[12]; ?></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest3" value="nr2">
</td>
<td width="320" height="20"><font face="verdana" size="1">b. <? echo $data[13]; ?></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest3" value="nr3">
</td>
<td width="320" height="20"><font face="verdana" size="1">c. <? echo $data[14]; ?></font></td>
</TR>
<TR>
<td height="20" colspan="2"></td>
</tr>
<TR>
<td colspan="2"><font face="verdana" size="1"><B>4. <? echo $data[4]; ?></B></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest4" value="nr1">
</td>
<td width="320" height="20"><font face="verdana" size="1">a. <? echo $data[15]; ?></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest4" value="nr2">
</td>
<td width="320" height="20"><font face="verdana" size="1">b. <? echo $data[16]; ?></font></td>
</TR>
<TR>
<td width="20" height="20">
<input type="radio" name="quest4" value="nr3">
</td>
<td width="320" height="20"><font face="verdana" size="1">c. <? echo $data[17]; ?></font></td>
</TR>
<TR>
<td height="20" colspan="2"></td>
</tr>
<TR>
<td colspan="2" width="340"><font face="verdana" size="1"><B>5. <? echo $data[5]; ?></B></font></td>
</TR>
<TR>
<td width="20" height="20" valign="middle">
<input type="radio" name="quest5" value="nr1" valign="middle">
</td>
<td width="320" height="20"><font face="verdana" size="1">a. <? echo $data[18]; ?></font></td>
</TR>
<TR>
<td width="20" height="20" valign="middle">
<input type="radio" name="quest5" value="nr2" valign="middle">
</td>
<td width="320" height="20"><font face="verdana" size="1">b. <? echo $data[19]; ?></font></td>
</TR>
<TR>
<td width="20" height="20" valign="middle">
<input type="radio" name="quest5" value="nr3">
</td>
<td width="320" height="20"><font face="verdana" size="1">c. <? echo $data[20]; } ?></font></td>
</TR>
<TR>
<TR>
<td height="10" colspan="2"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" class="email" value="Resultat"></td>
</form>
<TR>
<td height="10" colspan="2"></td>
</tr>
</table>
---------------------------------------------------
Er der nogen som har en idé til hvordan jeg tæller de rigtige svar???
På forhånd tak.
/Beldring
http://www.musikviden.dk
ps. = jeg havde tænkt på at de skulle være nogert i stil med
if (question1==<? echo $data[18]; ?>) { antal + 1}
or if (question2==<? echo $data[19]; ?>) { antal + 1}
-Hvor echo'et er de rigtige svar ... men hvad siger i?