【问题标题】:limit the number of the pagination pages限制分页页数
【发布时间】:2020-03-09 13:00:37
【问题描述】:
<?php

$limit = 1;
if (isset($_GET["page"])) {
$page  = $_GET["page"];
}
else{
$page=1;
};
$start_from = ($page-1) * $limit;
$result = mysqli_query($conn,"SELECT * FROM acxhuzur_dernek.video ORDER BY id LIMIT 
$start_from, $limit");

while($row = mysqli_fetch_array($result))
{
 $output.='
 <div class="col-6 col-md-4 blog-post blog-post-style1 sm-margin-30px-bottom wow fadeInUp" 
 data-wow-delay="0.2s" style="margin-bottom: 30px; visibility: visible; animation-delay: 
  0.2s; animation-name: fadeInUp;">
  <div class="text-center fit-videos overflow-hidden margin-nine-bottom sm-margin-20px- 
   bottom">
  <!-- start youtube video -->
  <iframe width="560" height="315" src="'.$row['video_link'].'; ?>" allowfullscreen></iframe>
<!-- end youtube video -->
</div>
<div class="separator-line-verticle-small-thick bg-deep-pink d-inline-block align-top margin-three-top margin-four-left sm-margin-10px-top" style="float: right"></div>
<div class="post-details width-75 lg-width-85 d-inline-block sm-width-85 text-md-right" style="float: right">
    <a href="#" class="post-title text-medium margin-four-bottom d-block text-extra-dark-gray sm-margin-10px-bottom">'.$row['video_text'].'</a>
    <span class="post-author font-weight-500 text-extra-small text-medium-gray text-uppercase d-block margin-two-bottom">'.dateformater($row['tarih']).'</span>
</div>
</div>
'; } echo $output; ?>

这里是分页链接

<?php
 $result_db = mysqli_query($conn,"SELECT COUNT(id) FROM acxhuzur_dernek.video ");
 $row_db = mysqli_fetch_row($result_db);
 $total_records = $row_db[0];
 $total_pages = ceil($total_records / $limit);
 $pagLink .= '
 <div class="col-12 margin-100px-top md-margin-50px-top wow" style="visibility: visible; 
 animation-name: fadeInUp;">
 <div class="pagination text-small text-uppercase text-extra-dark-gray text-center">
 <ul class="mx-auto">
  ';
   for ($i=1; $i<=$total_pages; $i++) {

  if($page == $i){
  $pagLink .= '
  <li class="active"><a href="gallery_video?page='.$i.'">'.$i.'</a></li>
   ';}else{ $pagLink .= '
  <li><a href="gallery_video?page='.$i.'">'.$i.'</a></li>
   ';}
  }
  echo $pagLink . '</ul>
                  </div>
                 </div>

   ';
   ?>

这是我用来创建用于数据搜索的分页页面的代码。但我只是注意到我有太多的记录,它会有太多的页码。我试图限制显示的页码,并寻找许多示例。有很多方法可以做到这一点,但我仍然不知道如何限制我的方法。 这段代码运行良好,但是我想限制分页块的页数,例如,

Prev 1 2 3 4 5 6 .. 40 41 Next

Prev 1 2 .. 6 7 8 9 10 .. 40 41 Next

【问题讨论】:

    标签: php html pagination


    【解决方案1】:

    我建议使用任何分页模块/库,例如https://packagist.org/?query=pagination,用于后端和任何库,例如datatables,用于前端。它们将为您节省大量时间和您将来会发现的问题。它们也可以根据您的需要进行样式设置。

    【讨论】:

      猜你喜欢
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 2012-01-11
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多