0

私は4つのはい/いいえの質問を含む短いクイズを作成しました。たとえば、ユーザーが2番目の質問をしているときにWebページを閉じた場合、ページを再度開いたときに( 30 日後まで) 残りの質問と同じ質問が表示されます。以下は、これまでに取得したコードの一部です。

<?php
session_set_cookie_params(2592000); //Sets cookie to last for 30 days
session_start();
?>

これは質問のコードです

//Variables for functions
 $number;
 $creature2;
 $creature3;
 //Function for showing questions 2 to 7
  function showquestion($number) {

      echo "<div class='questions'><form method ='GET' action='Creatures.php'>
     <input type='submit' name='answer$number' value='Yes' class='buttons' />
     <input type='submit' name='answer$number' value='No' class='buttons' />
     </form></div>";
 }

  //Function for showing questions 8 to 15
  function showanswer($creature2,$creature3) {
      echo "<div class='questions'><form method ='GET' action='Creatures.php'>
     <button type='submit' name='final' value='$creature2' class='buttons'> Yes </button>
     <button type='submit' name='final' value='$creature3' class='buttons'> No </button>
     </form></div>";
 }
//If start button has not been pressed, display nothing
if (!isset($_POST['start'])){

} //If start button has been pressed, display questions
else{ 
echo $firstquestion;
     echo "<div class='questions'><form method ='GET' action='Creatures.php'>
     <input type='submit' name='yes1' value='Yes' class='buttons' />
     <input type='submit' name='no1' value='No' class='buttons' />
     </form></div>";
}
//Question 2
if ($_GET['yes1']) //If answer to Q1 is yes then display this
{
echo "<div class='questions'><p>{$questions[0][0]}</p></div>";
showquestion(1);
}

//Question 3
if ($_GET['no1']) 
{
echo "<div class='questions'><p>{$questions[0][1]}</p></div>"; //If answer to Q1 is no then display this
showquestion(2);
}

//Questions 4 and 5
switch($_GET['answer1']) //If Question 2 is yes, do this
{
case 'Yes': echo "<div class='questions'><p>{$questions[1][0]}</p></div>";
showquestion(3);
break;
case 'No': echo "<div class='questions'><p>{$questions[1][1]}</p></div>";
showquestion(4);
}

//Questions 6 and 7
switch($_GET['answer2']) //If Question 3 is yes, do this
{
case 'Yes': echo "<div class='questions'><p>{$questions[1][2]}</p></div>";
showquestion(5);
break;
case 'No': echo "<div class='questions'><p>{$questions[1][3]}</p></div>";
showquestion(6);
}

//Questions 8 and 9
switch($_GET['answer3']) 
{
case 'Yes': echo "<div class='questions'><p>{$questions[2][0]}</p></div>";
showanswer('Eagle','Parrot');
break;
case 'No': echo "<div class='questions'><p>{$questions[2][1]}</p></div>";
showanswer('Ostrich','Turkey_(bird)');
}

//Questions 10 and 11
switch($_GET['answer4']) 
{
case 'Yes': echo "<div class='questions'><p>{$questions[2][2]}</p></div>";
showanswer('Grasshopper','Ant');
break;
case 'No': echo "<div class='questions'><p>{$questions[2][3]}</p></div>";
showanswer('Gorilla','Tiger');
}

//Questions 12 and 13
switch($_GET['answer5']) 
{
case 'Yes': echo "<div class='questions'><p>{$questions[3][0]}</p></div>";
showanswer('Penguin','Goose');
break;
case 'No': echo "<div class='questions'><p>{$questions[3][1]}</p></div>";
showanswer('Frog','Salamander');
}

//Questions 14 and 15
switch($_GET['answer6']) 
{
case 'Yes': echo "<div class='questions'><p>{$questions[3][2]}</p></div>";
showanswer('Octopus','Jellyfish');
break;
case 'No': echo "<div class='questions'><p>{$questions[3][3]}</p></div>";
showanswer('Goldfish','Eel');
}

以前に他の人がそうしているのを見たので、これが可能であることを知っています。クイズはこちらMy Quiz

4

0 に答える 0