mam problem ze zliczaniem poprawnych odpowiedzi w poniższym skrypcie (przerobiłem z wersji mysql).
w przypadku zapytania z limitem działa bez problemu:
$display = sqlite_query($db, "SELECT * FROM tabela ORDER BY id LIMIT 4");
ale przy losowych pytaniach nie liczy poprawnie:
$display = sqlite_query($db, "SELECT * FROM tabela ORDER BY RANDOM() LIMIT 4");
$db = sqlite_open('quiz.db');
//$display = sqlite_query($db, "SELECT * FROM tabela ORDER BY id LIMIT 4"); // okreslone rekordy z limitem
$display = sqlite_query($db, "SELECT * FROM tabela ORDER BY RANDOM() LIMIT 4"); // losowe rekordy
if (!@$_POST['submit'])
{
echo "<form method=post action=''>"; while ($row = sqlite_fetch_array($display))
{
$id = $row["id"];
$question = $row["question"];
$opt1 = $row["opt1"];
$opt2 = $row["opt2"];
$opt3 = $row["opt3"];
$answer = $row["answer"];
echo "<tr><td colspan=3><br><b>$question</b></td></tr>"; echo "<tr><td><input type=radio name='q$id' value=\"$opt1\"> $opt1</td></tr><tr><td><input type=radio name='q$id' value=\"$opt2\"> $opt2</td></tr><tr><td><input type=radio name='q$id' value=\"$opt3\"> $opt3</td></tr>"; }
echo "<input type='submit' value='See how you did' name='submit'>"; }
elseif ($_POST['submit'])
{
$score = 0;
$total = sqlite_num_rows($display);
while ($result = sqlite_fetch_array($display))
{
$answer = $result['answer'];
$q = "q$result[id]";
if (@$_POST[$q] == $answer)
{
$score++;
}
}
echo "<p align=center><b>You scored $score out of $total</b></p>"; }
w czym tkwi problem, nie mam już pomysłu, help (IMG:
style_emoticons/default/exclamation.gif) !
Ten post edytował shreker 8.03.2011, 01:25:44