转到页面时,如何使单选按钮保持选中状态?

时间:2019-06-26 12:53:13

标签: php

我是一名初学者,现在正忙于建立一个PHP在线测验网站,我在选择选项时遇到了一些问题。

进入下一页时,我需要我的单选按钮保持选中状态。

这是我的页面代码:

每次我单击“下一步”并返回上一页时,我的选择都会被删除。如何保存它?


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf=8">
        <title>PHP Quizzer</title>
    </head>

    <body>
        <header>
            <div class = "container">
                <h1>PHP Quizzer</h1>
            </div>
        </header>

        <main>
            <div class="container">
                <div class="current"> Question  <?php echo $question['question_number']; ?> of <?php echo $total; ?> </div>
                <p class="question">
                    <?php echo $question['text']; ?>
                </p>

                <form method="post" action="process.php">
                    <ul class="choices">

                        </select>

                        <?php while($row =$choices-> fetch_assoc()) : ?>
                        <li><input name="choice" type="radio" value="<?php echo $row['id']; ?>" /><?php echo $row['text'] ; ?></li>
                        <?php endwhile; ?>
                    </ul>

                    <input type="submit" value="Submit" />
                    <input type="hidden" value="<?php echo $number;?>" name="number"/>
                    <!--<a href="questions.php?n=1" class = "previous">Previous</a>-->
                    <!--<a href="questions.php?n=" name = "next">Next</a>-->

                    <?php
                        $next_button='';
                        $previous_button='';
                        $enabled='TRUE';
                        if ($number<$total)
                        {
                            $number++;
                            $next_button="<a href='questions.php?n=$number name='next'>Next</a>";
                            echo($next_button);
                        }

                        if ($number>2)
                        {
                            $number--;
                            echo "<a href='questions.php?n=" . ($number-1) . "' class='button'>Previous</a></li>";
                            #$previous_button="<a href='questions.php?n= name='previous'>Previous</a>";
                            echo($previous_button);
                        }
                    ?>
                </form>
            </div>
        </main>

        </header>

    </body>
</html>

<?php

    #if(count($id_list) < $num) {die("I need more questions in the database.");}
?>

这就是我的单选按钮所在的位置:

<?php while($row =$choices-> fetch_assoc()) : ?>
            <li><input name="choice" type="radio" value="<?php echo $row['id']; ?>" /><?php echo $row['text'] ; ?></li>
            <?php endwhile; ?>
        </ul>
        <input type="submit" value="Submit" />
        <input type="hidden" value="<?php echo $number;?>" name="number"/>

每次进入下一页时,我都需要保存选择。

0 个答案:

没有答案