나는 퀴즈 스크립트를 작성했으며 모두 잘 동작합니다. 지금하고 싶은 것은 미세 조정입니다.변수와 관련된 PHP 카운터 내용을 얻는 방법
6 개의 질문이 있습니다. 질문과 답변은 다음과 같은 변수로 정의됩니다.
$q7="(7) __________ you like the red one or the blue one? (Positive, simple present)";
$a7="(7) <strong>Do</strong> you like the red one or the blue one? (Positive, simple present)";
사람이 각 질문에 대답 할 때 각 정답을 증가시키는 카운터가 있습니다.
나는 카운터를보고 정확한 숫자의 응답을 볼 수 있지만 숫자 일뿐입니다.
사람이 내가 그들에게이 같은 점수를 보여 3 정확한 6에서 들어간 경우 -
You got 3/6 correct.
내가 또한 그들에게 3 개 정확한 그들이 선택한 답변, 그리고 잘못된 응답을 보여되고 싶지.
이것이 가능합니까? 카운터에 3 개의 정답이 있음을 알고 있다면 어떻게 알 수 있습니까? 그 특별한 변수들?
$ counter에 4 자리 이하의 정답이 포함되어있는 경우 어떻게 대답합니까? 그 대답을 표시합니다. 다른 사람이 말했듯이
// *** question 12 *** //
print "<p> </p><table id='english_nb'><tr>";
print "<th>$q12</th></tr></table>";
print "<table id='english_nb'><tr>";
if ($_POST['answer12']==$do)
print "<td width='25%'><input type='radio' checked='checked' name='answer12' value='$do' />$do</td>";
else
print "<td width='25%'><input type='radio' name='answer12' value='$do' />$do</td>";
if ($_POST['answer12']==$didnt){
print "<td width='25%'><input type='radio' checked='checked' name='answer12' value='$didnt' />$didnt</td>";
$correct++;
}
else
print "<td width='25%'><input type='radio' name='answer12' value='$didnt' />$didnt</td>";
if ($_POST['answer12']==$doesnt)
print "<td width='25%'><input type='radio' checked='checked' name='answer12' value='$doesnt' />$doesnt</td>";
else
print "<td width='25%'><input type='radio' name='answer12' value='$doesnt' />$doesnt</td>";
if ($_POST['answer12']==$did)
print "<td width='25%'><input type='radio' checked='checked' name='answer12' value='$did' />$did</td>";
else
print "<td width='25%'><input type='radio' name='answer12' value='$did' />$did</td>";
print "</tr></table>";
// *** check the answers *** //
foreach ($_POST as $value){
if (isset ($value)){
$done++;
}
}
if ($done !=7) //set this to 1 higher than the number of questions and answers
print "<input type='submit' name='submit' value='Check answers' />";
if (($correct<5)&&($done==7)) //set this to the number of minimum correct answers
print "<p>You should review the information and try the quiz again.</p>";
print "<p>Your score is $correct/6 correct.</p>"; //set this to the same number of questions and answers
if (($done > 0)&&($done < 7)) //set this to 1 higher than the number of questions and answers
print "<p>You haven't answered all the questions. Please finish the quiz and re-submit your answers.</p>";
if(($done==7)&&($correct>4))
{ //set this to 1 higher than the number of questions and answers
print "<p>Your score is $correct/6 correct.</p>"; //set this to the same number of questions and answers
if ($correct==0)
$correct='0';
else
{
print "<p>The correct answers:</p>";
print "<p>$a7</p>";
print "<p>$a8</p>";
print "<p>$a9</p>";
print "<p>$a10</p>";
print "<p>$a11</p>";
print "<p>$a12</p>";
'$의 a7'과'$ q7' 그들을 보여줄 수? 배열에 대해 배워야합니다. '$ a [1] = '대답 1'; $ a [2] = 'answer2'' 등 ... –
변수를 사용하는 대신'array()'를 사용하는 것이 더 낫습니다. 예를 들어'array()'질문을 사용하고 다른'array()'는 각 질문의 답. –