【问题标题】:Bootstrap table pagination with MySQL and PHP使用 MySQL 和 PHP 进行引导表分页
【发布时间】:2014-04-11 18:21:35
【问题描述】:

我有一个 mysql 数据库,它正在选择 $name = kicked 的结果,

这会返回几个结果(通常是 50+)

我不知道如何对结果进行分页 - 帮助?

这是我的表的代码:

<div class="tab-pane" id="2">

    <br>

  <table class="table table-bordered table-striped">
    <thead>
      <tr>
        <th>Kicker</th>
        <th>Kick Reason</th>
      </tr>
    </thead>
    <tbody id="myTable">
        <?php
          $kicks = mysql_query("select * from Kicks where kicked = '$name'");




while($row = mysql_fetch_array($kicks)) 
  {
        echo "<tr>";
  echo "<td>" . $row['kicker'] . "</td>";
  echo "<td>" . $row['reason'] . "</td>";
  echo "</tr>";
  } ?>
    </tbody>
    </table>
  <ul class="pagination pagination-lg pager" id="myPager"></ul>

</div>

【问题讨论】:

    标签: javascript php mysql pagination twitter-bootstrap-3


    【解决方案1】:

    您应该考虑使用 Mysql LIMIT 子句。它允许您从表中从偏移量 y 开始选择 x 个元素。可以通过将页码参数传递给您的页面来确定偏移量。

    伪代码:

    .../page.php?pagenumber=2

    $iPerPage = 10;
    $iOffset = (pagenumber - 1) * $iPerPage;
    SELECT ... FROM `kicks` LIMIT $iOffset, $iPerPage;
    

    看到这个link

    【讨论】:

      猜你喜欢
      • 2015-01-15
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 2011-04-25
      • 1970-01-01
      • 2015-05-16
      相关资源
      最近更新 更多