php - 使用 Bootstrap 对 PHP 和 MYSQL 进行分页

标签 php mysql twitter-bootstrap pagination

我的数据库中有很多数据(包括图像、描述等),这些数据不合理地留在一页中。 如何使用 php、mysql 和 bootstrap 进行分页?

enter image description here

 <?php

    $query = "SELECT Title, Painter_Name, Description, Year, Image FROM paintings, painters WHERE painters.ID = paintings.Painter_ID";

        $query_run = mysqli_query($connection, $query);

        while($row = mysqli_fetch_assoc($query_run)) {
      $title = $row['Title'];
      $painter = $row['Painter_Name'];
      $description = $row['Description'];
      $image = $row['Image'];
      $year = $row['Year'];
    ?>

      <div id="contatiner">

    <?php
      echo "
      <div class=\"row\">
        <div class=\"offset-sm-2 col-sm-8 offset-sm-2\"> 
            <div class=\"card\">
              <div class=\"card-block\">
                <h4 class=\"card-title text-sm-center\">$title ($year)</h4>
                <h6 class=\"card-subtitle text-sm-center text-muted\">$painter</h6>
              </div>
              <p class=\"text-sm-center\"><img style=\"width:300px; height:300px;\" src=\"$image\" alt=\"Card image\"></p>
              <div class=\"card-block\">
                <p class=\"card-text text-sm-center\">$description</p>
                <p class=\"text-sm-center\"><a href=\"#\" class=\"card-link\">Add to favorites</a></p>
              </div>
            </div>
        </div>
      </div>
         ";
        }
    ?>
    </div>
<小时/>
<nav class="text-xs-center">
    <ul class="pagination">
        <li class="page-item">
            <a href="#" class="page-link" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
                <span class="sr-only">Previous</span>
            </a>
        </li>
        <li class="page-item"><a class="page-link" href="#">1</a></li>
        <li class="page-item"><a class="page-link" href="#">2</a></li>
        <li class="page-item"><a class="page-link" href="#">3</a></li>
        <li class="page-item"><a class="page-link" href="#">4</a></li>
        <li class="page-item"><a class="page-link" href="#">5</a></li>
        <li class="page-item">
            <a href="#" class="page-link" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
                <span class="sr-only">Next</span>
            </a>
        </li>
    </ul>
</nav>

我浏览过互联网,但现在不知道从何开始...

提前致谢!

最佳答案

您可以使用限制和偏移量进行查询:https://dev.mysql.com/doc/refman/5.5/en/select.html

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

从 tbl LIMIT 5,10 中选择*; # 检索第 6-15 行

例如,第 1 页的偏移量为 0,限制为 10,每页您将偏移量和限制增加 10(或任何您想要的值)。

您可以使用 $_GET var 指定页面 id,或使用不同的样式; MVC或者获取url的一部分。

关于php - 使用 Bootstrap 对 PHP 和 MYSQL 进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40473870/

相关文章:

javascript - jQuery Datepicker 错误显示

php - 比较 mysql 和 php 中的两个数组

mysql - mysql中如何使用join和union进行子查询

javascript - JQuery 追加元素超出父 div 宽度?

html - 具有相同宽度的按钮和按钮组

php - 如何运行 php 脚本来发送推送通知

php - 在回显之前编辑字符串中的 url?

html - Bootstrap 3.0 col-sm-offset-1 正在影响 md 和 lg 设备

php - Robots.txt 和谷歌日历

php - 使用 MySQL 动态创建日期周期