我正在寫一個測驗。首先問題顯示在question.php中,然後在answer.php中,答案是分析,如果答案是正確的話這個單詞存儲在一個數組中,如果錯誤在另一個。然後回到question.php等等。當沒有更多的問題時,result.php將顯示哪些單詞是正確的,哪些單詞是錯誤的。將幾個單詞存儲在會話數組中,然後顯示它們
請注意,每次加載answer.php時,session數組都需要包含一個新單詞。
編輯:問題是,會話陣列僅存儲第一項
我的代碼:
answer.php:
<?php
session_start();
$question = $_GET['question'];
$user_answer = $_GET['user_answer'];
$right_answer = mysql_query("SELECT french FROM words where english='$question'");
$fila = mysql_fetch_assoc($right_answer);
$fila_french = $fila['french'];
if ($user_answer == $fila_french) {
echo "Right";
$_SESSION['right_words'] = array();
array_push($_SESSION['right_words'], $question);
}
else { echo "Wrong";
$_SESSION['wrong_words'] = array();
array_push($_SESSION['wrong_words'], $question);
}
echo "<a href='question.php' > Next </a>";
?>
result.php:
<?php
session_start();
$right_answers = implode(',',$_SESSION['right_words']);
$wrong_answers = implode(',',$_SESSION['wrong_words']);
echo "<h1> You finished the test </h1>
<p> You have these words right: $right_answers</p>
<p> You have these words wrong: $wrong_answers</p>
<a href='../exercises.php'> Go back to exercises </a>";
?>
感謝您的幫助!
你的意思[破滅()](http://php.net/implode )? – Touki