如何在分数页面后的同一页面上显示用户的答案和正确的答案

I am currently stuck at the answer page for about a week already, it's very depressing. How do I carry forward what the user have chosen and showed the correct answer in the worksheet/question page, when I click "Review Your Answers" button.

Here's my question page:

<!DOCTYPE html>
<head>
<title> English Kaki </title>
    <link rel="stylesheet" href="bootstrap.css">
    <script src="https://code.jquery.com/jquery.js"></script>
    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
    <link rel = "stylesheet" type = "text/css" href = "Main.css">
</head>

<body>
    <?php include_once"Header.php" ?>

    <div class="container-fluid">

            <div class="container">
                    <center><font color ="#FF9900"><h1>Sentence Structure</h1></font>
                    <p>Be our buddy, construct with us.</p> </center>
                </div>
      <div class="col-md-12" style="background-color:#ECEBEB;">

        <div class="row">
        <div class="col-sm-2" style="background-color:#ECEBEB;">
        </div>
        <div class="col-sm-6" style="background-color:#ECEBEB;">

            <?php

                $id=isset($_GET['id'])? $_GET['id']: '';
                $data= array(
                'Gws1'              =>array(
                'Name'              =>'Grammar Worksheet 1',
                'Questions'          =>' 
                <form action="SSresultPage.php?id=1" method="post">
                                <fieldset>
                                <ol>
                                        <li>
                                        <p>This is question 1 of Gws1 </p>
                                        <ul id="Gws1_questions1_options">
                                        <li><input id="Gws1_questions1_options" name="Gws1_questions1_options" type="radio" value="q1 option1" /><label>q1 option1</label></li>
                                        <li><input id="Gws1_questions1_options" name="Gws1_questions1_options" type="radio" value="q1 option2" /><label>q1 option2</label></li>
                                        <li><input id="Gws1_questions1_options" name="Gws1_questions1_options" type="radio" value="q1 option3" /><label>q1 option3</label></li>
                                        <li><input id="Gws1_questions1_options" name="Gws1_questions1_options" type="radio" value="q1 option4" /><label>q1 option4</label></li>
                                        </ul>
                                        </li>

                                        <br>

                                        <li>
                                        <p>This is question 2 of Gws1</p>
                                        <ul id="Gws1_questions2_options">
                                        <li><input id="Gws1_questions2_options" name="Gws1_questions2_options" type="radio" value="q2 option1" /><label>q2 option1</label></li>
                                        <li><input id="Gws1_questions2_options" name="Gws1_questions2_options" type="radio" value="q2 option2" /><label>q2 option2</label></li>
                                        <li><input id="Gws1_questions2_options" name="Gws1_questions2_options" type="radio" value="q2 option3" /><label>q2 option3</label></li>

                                        </ul>
                                        </li>

                                        <br>

                                        <li>
                                        <p>This is question 3 of Gws1</p>
                                        <ul id="Gws1_questions1_options">
                                        <li><input id="Gws1_questions3_options" name="Gws1_questions3_options" type="radio" value="q3 option1" /><label>q3 option1</label></li>
                                        <li><input id="Gws1_questions3_options" name="Gws1_questions3_options" type="radio" value="q3 option2" /><label>q3 option2</label></li>
                                        <li><input id="Gws1_questions3_options" name="Gws1_questions3_options" type="radio" value="q3 option3" /><label>q3 option3</label></li>
                                        </ul>
                                        </li>

                                </ol>
                                </fieldset> 
                                <input type="submit" value="Get Result"/>
                                </form>'
                ),

                'Gws2'              =>array(
                'Name'              =>'Grammar Worksheet 2',
                'Questions'          =>' <form action="SSresultPage.php?id=2" method="post">

                <input type="submit" value="Get Result"/>
                                </form>'
                ),

                'Gws3'              =>array(
                'Name'              =>'Grammar Worksheet 3',
                'Questions'          =>' <form action="SSresultPage.php?id=3" method="post">

                <input type="submit" value="Get Result"/>
                                </form>'
                ),

                'Vws1'              =>array(
                'Name'              =>'Vocabulary Worksheet 1',
                'Questions'          =>' <form action="SSresultPage.php?id=4" method="post">
                <fieldset>
                                <ol>
                                        <li>
                                        <p>Excuse me, my meal is cold. Could you please ________ for me?</p>
                                        <ul id="Vws1_questions1_options">
                                        <li><input id="Vws1_questions1_options" name="Vws1_questions1_options" type="radio" value="q1 option1" /><label>make it warmer</label></li>
                                        <li><input id="Vws1_questions1_options" name="Vws1_questions1_options" type="radio" value="q1 option2" /><label>warm it up</label></li>
                                        </ul>
                                        </li>
                                        <br>
                                        <li>
                                        <p>The ________ in most high end restaurants is usually excellent.</p>
                                        <ul id="Vws1_questions2_options">
                                        <li><input id="Vws1_questions2_options" name="Vws1_questions2_options" type="radio" value="q2 option1" /><label>service</label></li>
                                        <li><input id="Vws1_questions2_options" name="Vws1_questions2_options" type="radio" value="q2 option2" /><label>responsibility</label></li>
                                        </ul>
                                        </li>
                                        <br>
                                        <li>
                                        <p>I felt very _____ after the buffet.</p>
                                        <ul id="Vws1_questions3_options">
                                        <li><input id="Vws1_questions3_options" name="Vws1_questions3_options" type="radio" value="q3 option1" /><label>complete</label></li>
                                        <li><input id="Vws1_questions3_options" name="Vws1_questions3_options" type="radio" value="q3 option2" /><label>full</label></li>
                                        </ul>
                                        </li>

                                </ol>
                                </fieldset>         
                <input type="submit" value="Get Result"/>
                                </form>'
                ),

                'Vws2'              =>array(
                'Name'              =>'Vocabulary Worksheet 2',
                'Questions'          =>' <form action="SSresultPage.php?id=5" method="post">

                <input type="submit" value="Get Result"/>
                                </form>'
                ),

                'Vws3'              =>array(
                'Name'              =>'Vocabulary Worksheet 3',
                'Questions'         =>' <form action="SSresultPage.php?id=6" method="post">

                <input type="submit" value="Get Result"/>
                                </form>'
                )
                );


                if(isset($id) || $id){
                echo "<h2>{$data[$id]['Name']}</h2>";
                echo "<h4>Please choose the best option to complete the sentence.</h4>{$data[$id]['Questions']}";
                }

            ?>
        </center>
        </div>
        </div>
        </div>

        </div>
            <div class="col-sm-3" style="background-color:#ECEBEB;"></div>

        </div>
    <br><br>
    <?php include_once"Footer.php" ?>

</body>
</html>

Here's my result page:

<!DOCTYPE html>
<head>
<title> English Kaki </title>
    <link rel="stylesheet" href="bootstrap.css">
    <script src="https://code.jquery.com/jquery.js"></script>
    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
    <link rel = "stylesheet" type = "text/css" href = "Main.css">
</head>

<body>
    <?php include_once"Header.php" ?>

    <div class="container-fluid">

            <div class="container">
                    <center><font color ="#FF9900"><h1>Sentence Structure</h1></font>
                </div>
      <div class="col-md-12" style="background-color:#ECEBEB;">

            <center>
            <?php
            $fid = $_GET['id'];

                if ($fid == 1){
                    if(!empty($_POST['Gws1_questions1_options']) && !empty($_POST['Gws1_questions2_options']) && !empty($_POST['Gws1_questions3_options'])){
                    $answer1 = $_POST['Gws1_questions1_options'] && $answer2 = $_POST['Gws1_questions2_options'] && $answer3 = $_POST['Gws1_questions3_options'];

                                     $score =0;

                                     if ($answer1 == "q1 option1"){$score++;}
                                     if ($answer2 == "q2 option1"){$score++;}
                                     if ($answer3 == "q3 option1"){$score++;}

                                    echo "<h3>I'm proud of you for completing the worksheet!</h3>";
                                    echo "<h2>Your score is  $score/3</h2><br>";
                                    echo "Review your answers and find out where you went wrong!<br><br>";
                                    echo "<center><form action='SSanswerPage.php'>
                <input type = 'submit' value = 'Review your answers' class='btn'/>
                </form><center><br><br>";
                }                   
                else {
                echo '<p><font color="red">You must answer all questions before you can get your result.</font></p>';
                }}

                elseif ($fid == 2){

                    echo"2";

                }

                elseif ($fid == 3){

                    echo"3";

                }

                elseif ($fid == 4){

                                    $answer1 = $_POST['Vws1_questions1_options'];
                                    $answer2 = $_POST['Vws1_questions2_options'];
                                    $answer3 = $_POST['Vws1_questions3_options'];

                                     $score =0;

                                     if ($answer1 == "q1 option2"){$score++;}
                                     if ($answer2 == "q2 option1"){$score++;}
                                     if ($answer3 == "q3 option2"){$score++;}

                                    echo "<h3>I'm proud of you for completing the worksheet!</h3>";
                                    echo "<h2>Your score is  $score/3</h2><br>";
                                    echo "Review your answers and find out where you went wrong!<br><br>";
                                    echo "<center><form action='SSanswerPage.php'>
                <input type = 'submit' value = 'Review your answers' class='btn'/>
                </form><center><br><br>";

                }

                elseif ($fid == 5){

                    echo"5";

                }

                elseif ($fid == 6){

                    echo"6";

                }
            ?>

        </center>
        </div>
        </div>
            <div class="col-sm-3" style="background-color:#ECEBEB;"></div>

        </div>
    <br><br>
    <?php include_once"Footer.php" ?>

</body>
</html>

Only Grammar Worksheet 1 have questions and can compute score for now.
Thank you in advance.

dongren4758
dongren4758 如何显示此测验的答案myphpquiz.com/question.php?qid=1。在问题本身中显示正确的答案和描述。对不起,我真的需要帮助这部分@Gavriel
4 年多之前 回复
doujing9972
doujing9972 我知道使用$_POST['...'];但是如何将整个页面发布到答案页面?然后在每个问题的侧面显示正确的答案?@Gavriel
4 年多之前 回复
dongzhanjuan5141
dongzhanjuan5141 阅读会议。例如:tizag.com/phpT/phpsessions.php或tutorialspoint.com/php/php_sessions.htm或google.co.il/search?q=php+session+tutorial
4 年多之前 回复

1个回答

Let's say you have Q1, with possible answers A1,A2,A3. You know that the correct answer is Q2, and you see from $_POST['Q1'] == 'A3' that the user answered the wrong answer A3:

css:

.user {color:red}
.correct {color:blue}
.correct.user {color:green}

php:

function is_correct_class($correct_answer, $current_answer, $user_answer) {
  $class = $correct_answer == $current_answer ? 'correct' : '';
  $class .= $user_answer == $current_answer ? ' user' : '';
  return $class;
}

<h2>Q1</h2>
<h3 class="<?php echo is_correct_class('A2', 'A1', $_POST['Q1']);?>;">A1</h3>
<h3 class="<?php echo is_correct_class('A2', 'A2', $_POST['Q1']);?>;">A2</h3>
<h3 class="<?php echo is_correct_class('A2', 'A3', $_POST['Q1']);?>;">A3</h3>
doucang6914
doucang6914 你需要了解html,表单和一些php的基础知识。 请寻找一个好的教程,并回答一些具体的问题
4 年多之前 回复
doujia1904
doujia1904 我是否从结果或问题页面获得了价值? @Gavriel
4 年多之前 回复
ds78662302
ds78662302 您对所有可能的答案使用is_correct_class函数:A1,A2,A3。 它需要知道您现在正在绘制哪条线。 所以你需要将它传递给函数。 在这个例子中,它全部手动传递3个答案
4 年多之前 回复
dongzhang7157
dongzhang7157 目前的答案是什么? @Gavriel
4 年多之前 回复
doufulian4076
doufulian4076 css做到了。 正确猜到答案:绿色,当用户犯了错误时,他猜是红色,正确答案是蓝色。 颜色可以在CSS中更改。
4 年多之前 回复
doujiaozhan4397
doujiaozhan4397 我想用'q1 option1'等替换$ correct_answer,$ current_answer,$ user_answer? 目前的答案是不是需要对吗? 只需要检查一下是否正确答案=用户答案..你在哪里为PHP代码中的答案分配颜色..对不起我真的迷路了..
4 年多之前 回复
dsdeeaquu38538545
dsdeeaquu38538545 在答案页面。 这就是您回答后可能出现的问题
4 年多之前 回复
donglanzhan7151
donglanzhan7151 PHP代码假设在哪里? 在我的问题页面? :(
4 年多之前 回复
dongtang5229
dongtang5229 谢谢,但是......我创建了一个新文件“SSanswerPage.php”。 用户的回答是问题页面? 所以我在<form action =“SSresultPage.php?id = 1”method =“post”>下面放了另一个<form action =“SSanswerPage.php?id = 1”method =“post”>? 对不起,我很喜欢这个帖子功能。 @gavriel
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐