如何按顺序显示结果?

gorkyyrv  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(336)

我在为测验设计一个表格。数据库里有15个问题。我想显示10个问题的用户与洗牌,但我有困难显示问题的顺序。
我的php代码是:

<form action="includes/backend_quiz.php" method="post">
    <?php
        $query=mysqli_query($conn, "SELECT * FROM quiz order by rand() LIMIT 10") or die("Could not retrieve data: " .mysqli_error($conn));

            if (mysqli_num_rows($query) > 0){           
                while($row = mysqli_fetch_assoc($query)){               
                    extract($row);  

                    ?>
                        <input type="hidden" name="id" value="<?php echo $id ?>" />
                        <h4><?php echo $id ?>.&nbsp  <?php echo $quation; ?></h4><br />

                        <input type="radio" name="response" value="a" /> <?php echo $opt1;?><br />
                        <input type="radio" name="response" value="b" /> <?php echo $opt2;?><br />
                        <input type="radio" name="response" value="c" /> <?php echo $opt3;?><br />
                        <input type="radio" name="response" value="d" /> <?php echo $opt4;?><br />
                        <br />
                    <?php

            }
        }       
    ?>
    <input type="submit" name="ans" value="Finish"/>
</form>

输出:

那么,如何按顺序显示问题,如q1、q2、q3等。?

biswetbf

biswetbf1#

试试这个

<form action="includes/backend_quiz.php" method="post">
<?php
    $query=mysqli_query($conn, "SELECT * FROM quiz order by rand() LIMIT 10") or die("Could not retrieve data: " .mysqli_error($conn));
        if (mysqli_num_rows($query) > 0){
            $number = 0;           
            while($row = mysqli_fetch_assoc($query)){               
                extract($row);  
                $number++;
                ?>
                    <input type="hidden" name="id" value="<?php echo $id ?>" />
                    <h4><?php echo $number?>.&nbsp  <?php echo $quation; ?></h4><br />

                    <input type="radio" name="response" value="a" /> <?php echo $opt1;?><br />
                    <input type="radio" name="response" value="b" /> <?php echo $opt2;?><br />
                    <input type="radio" name="response" value="c" /> <?php echo $opt3;?><br />
                    <input type="radio" name="response" value="d" /> <?php echo $opt4;?><br />
                    <br />
                <?php

        }
    }       
?>
<input type="submit" name="ans" value="Finish"/>

相关问题