<tfoot id='VJ1gm'></tfoot>
<i id='VJ1gm'><tr id='VJ1gm'><dt id='VJ1gm'><q id='VJ1gm'><span id='VJ1gm'><b id='VJ1gm'><form id='VJ1gm'><ins id='VJ1gm'></ins><ul id='VJ1gm'></ul><sub id='VJ1gm'></sub></form><legend id='VJ1gm'></legend><bdo id='VJ1gm'><pre id='VJ1gm'><center id='VJ1gm'></center></pre></bdo></b><th id='VJ1gm'></th></span></q></dt></tr></i><div id='VJ1gm'><tfoot id='VJ1gm'></tfoot><dl id='VJ1gm'><fieldset id='VJ1gm'></fieldset></dl></div>

    <small id='VJ1gm'></small><noframes id='VJ1gm'>

      <legend id='VJ1gm'><style id='VJ1gm'><dir id='VJ1gm'><q id='VJ1gm'></q></dir></style></legend>
        <bdo id='VJ1gm'></bdo><ul id='VJ1gm'></ul>
    1. 如何查看用户在测验中的选择是否正确?

      How can I see if the user#39;s choice in the quiz is correct?(如何查看用户在测验中的选择是否正确?)
        <tbody id='DChIl'></tbody>

    2. <small id='DChIl'></small><noframes id='DChIl'>

        <tfoot id='DChIl'></tfoot>

          <bdo id='DChIl'></bdo><ul id='DChIl'></ul>
          <i id='DChIl'><tr id='DChIl'><dt id='DChIl'><q id='DChIl'><span id='DChIl'><b id='DChIl'><form id='DChIl'><ins id='DChIl'></ins><ul id='DChIl'></ul><sub id='DChIl'></sub></form><legend id='DChIl'></legend><bdo id='DChIl'><pre id='DChIl'><center id='DChIl'></center></pre></bdo></b><th id='DChIl'></th></span></q></dt></tr></i><div id='DChIl'><tfoot id='DChIl'></tfoot><dl id='DChIl'><fieldset id='DChIl'></fieldset></dl></div>
          <legend id='DChIl'><style id='DChIl'><dir id='DChIl'><q id='DChIl'></q></dir></style></legend>
              • 本文介绍了如何查看用户在测验中的选择是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试检查用户选择的答案是否正确,但无法正常工作:

                I am trying to check if the answer that the user chose was correct, but it doesn't work properly:

                                        <form method="post">
                                        <?php
                                            $question = mysql_query("SELECT * FROM `questions`");
                                            $stat = mysql_fetch_assoc($question);
                                            $num = mysql_num_rows($question);
                                            $questionid = 0;
                                            for($i=0;$i<=$num;$i++)
                                            {
                                                $question = mysql_query("SELECT * FROM `questions` WHERE `id`='$i'");
                                                $stat = mysql_fetch_assoc($question);
                                                //if($stat['answer'] == null
                                                echo $stat['question'] . '<br />';
                                                echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer1']."<br />";
                                                echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer2'] . '<br />';
                                                echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer3'] . '<br />';
                                                echo '<input type="radio" name="a'.$x.'" value="'.$x.'" />' .$stat['answer4'] . '<br />';
                                                $questionid++;
                                                $x = $x+1;
                                            }
                                            echo $result;
                                        ?>
                                        <input type="submit" name="go" value="Go" />
                                    </form>
                

                那部分基本上:

                $x = 1;
                $question = mysql_query("SELECT * FROM `questions`");
                $stat = mysql_fetch_assoc($question);
                $num = mysql_num_rows($question);
                if(isset($_POST['go']))
                {
                    for($i=0;$i<$num;$i++)
                    {
                        if ($_POST['ans'.$x] == $row['correct']) 
                        { 
                            $result = $result + 1; 
                        }
                        $x = $x + 1;
                    }
                }
                

                由于某种原因它没有正确发布结果,我认为代码有问题,希望得到帮助.

                For some reason it doesn't post the results properly and I think something is wrong with the code, would appreciate help.

                推荐答案

                这是帮助您的另一种尝试.

                Here's another attempt at helping you.

                我实际上写了一个完整的解决方案",在这个过程中发现了你的代码中的一些小错误 - 还有一些我无法理解的东西.

                I actually wrote a "complete solution", and in the process discovered a few little bugs in your code - plus some things I just couldn't understand.

                主要错误:您所有的单选按钮都具有相同的值 ($x),因此无论您为问题 1 按下哪个按钮,答案都是1",等等.您还做了其他一些我无法完成的事情弄清楚 - 所以我所做的是创建一个简单的流程 - 一个页面提出问题,另一个页面评估结果.

                Principal bug: all your radio buttons have the same value ($x), so no matter what button you press for question 1, the answer is "1", etc. There were other things you did that I could not quite figure out - so what I did instead was create a simple flow - one page that asks the questions, and another that evaluates the results.

                问题页面(我混淆了数据库的访问参数 - 不,我不使用密码"作为我的密码!):

                Question page (I obfuscated access parameters for my database - no, I don't use "password" as my password!):

                <html>
                <body>
                <form action="./evaluate.php" method="post">
                <?php
                $server = mysql_connect ('localhost', 'username, 'password');
                mysql_select_db("questionnaire", $server);
                
                $question = mysql_query("SELECT * FROM `Questions`;");
                $x = 0;
                while ($row = mysql_fetch_assoc($question))
                {
                   echo $row['question'] . '<br />';
                   echo '<input type="radio" name="a'.$x.'" value=1 />' .$row['answer1'] . '<br />';
                   echo '<input type="radio" name="a'.$x.'" value=2 />' .$row['answer2'] . '<br />';
                   echo '<input type="radio" name="a'.$x.'" value=3 />' .$row['answer3'] . '<br />';
                   echo '<input type="radio" name="a'.$x.'" value=4 />' .$row['answer4'] . '<br />';
                   $x = $x + 1;
                
                }
                mysql_close($server);
                ?>
                
                <input type="submit" name="Submit" value="Submit" />
                <br>
                </form>
                </body>
                </html>
                

                和评估.php:我稍微更改了代码以使输出更清晰",并添加红色/绿色触摸以显示已正确和错误回答的问题.显然,如果您愿意,您可以更进一步...

                and evaluate.php: I changed the code a bit to make the output "cleaner", and add a red/green touch to show questions that had been answered correctly and incorrectly. Obviously you can take these things much further if you want...

                <html>
                <body>
                
                <?php
                $server = mysql_connect ('localhost', 'username', 'password');
                mysql_select_db("questionnaire", $server);
                
                $question = mysql_query("SELECT * FROM `Questions`;");
                $x = 0;
                $score = 0;
                while ($row = mysql_fetch_assoc($question))
                {
                    echo $row['question'] . '?<br />';
                
                    $answered = $row['answer'.$_POST['a'.$x]] ;
                    $correct = $row['correct'] ;
                
                    if ($answered == $correct ) {
                        $score++;
                        $acolor = 'green' ;
                    }
                    else {
                        $acolor = 'red' ;
                    }
                
                    echo 'you answered <font color=' . $acolor . '>' . $answered . '<font color=black> <br />';
                
                
                    echo 'the correct answer was ' . $correct . '<br />' ;
                    echo '-------------------------------------- <br />' ;
                
                    $x = $x + 1;
                }
                echo 'You had a total of ' . $score . ' out of ' . $x . ' questions right!';
                mysql_close($server);
                ?>
                
                </body>
                </html>
                

                这产生了(对于我做的一个简单的三问题多项选择)预期的结果.让我知道它是否适合您!

                This produced (for a simple three-question multiple choice I made) the expected results. Let me know if it works for you!

                这篇关于如何查看用户在测验中的选择是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  • <bdo id='g3P6o'></bdo><ul id='g3P6o'></ul>
                      <tbody id='g3P6o'></tbody>
                    <i id='g3P6o'><tr id='g3P6o'><dt id='g3P6o'><q id='g3P6o'><span id='g3P6o'><b id='g3P6o'><form id='g3P6o'><ins id='g3P6o'></ins><ul id='g3P6o'></ul><sub id='g3P6o'></sub></form><legend id='g3P6o'></legend><bdo id='g3P6o'><pre id='g3P6o'><center id='g3P6o'></center></pre></bdo></b><th id='g3P6o'></th></span></q></dt></tr></i><div id='g3P6o'><tfoot id='g3P6o'></tfoot><dl id='g3P6o'><fieldset id='g3P6o'></fieldset></dl></div>
                      <legend id='g3P6o'><style id='g3P6o'><dir id='g3P6o'><q id='g3P6o'></q></dir></style></legend>

                      <small id='g3P6o'></small><noframes id='g3P6o'>

                          <tfoot id='g3P6o'></tfoot>