dongyulan6251 2018-10-22 15:49
浏览 96

如何使用分页每页显示1条记录?

I want to display one record per page through pagination untill all the records are displayed, navigation to pages must be like, Next Previous Finish. Here is my code to view the records from questions table.

<form class="form-horizontal" role="form" id='login' method="post" action="result.php">

                <?php
                $number_question = 1;
                $limit=10;
                $row = mysqli_query( $conn, "select id,question_name,image from questions where category_id=$category and level_id=$level ORDER BY RAND() LIMIT $limit");
                $total = mysqli_num_rows( $row );
                $page = $total/$number_question;
                $j = 1; $k = 1;
                ?>
                <?php while ( $result = mysqli_fetch_assoc($row) ) {
                                 ?>
                    <div id='question<?php echo $k;?>' >
                    <p class='questions' id="qname<?php echo $j;?>"> <?php echo $k?>.<?php echo $result['question_name'];?></p>
                    </br>
                     <?php echo '<img src="data:image/png;base64,'.base64_encode($result['image']).'" />'; ?></br><br/>
                     <input type="text" name="answer" placeholder="Enter your answer"  required />
                    <br/>
                <br/>
                    </div>
                    <?php


                        if ( $total > $number_question  ) {
                            if ( $j == 1 ) {
                                echo "<button id='".$j."' class='next btn btn-primary' type='button'>Next</button>";
                                echo "</div>";
                                $j++;           
                            } elseif ( $k == $total ) { 
                                echo " <button id='".$j."' class='previous btn btn-primary' type='button'>Previous</button>
                                            <button id='".$j."' class='next btn btn-primary' type='submit'>Finish</button>";
                                echo "</div>";

                                $j++;
                            } elseif ( $j > 1 ) {
                                echo "<button id='".$j."' class='previous btn btn-primary' type='button'>Previous</button>
                                            <button id='".$j."' class='next btn btn-primary' type='button' >Next</button>";
                                echo "</div>";

                                $j++;
                            }

                         }

                          $k++;
                     } ?>   
            </form>

The result of my code is : enter image description here

Can Someone help me please to use pagination? Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向