donpvtzuux37724 2015-07-23 09:21
浏览 168

限制分页页数

I have one page where I echo 10 items from MySql DB and has pagination for next page. The problem is that there are 1000+ rows in database.. so you can guess how many pages are in pagination links. How can I limit their numbers for example to show

1 2 3 4 5 ... N

when user change to page 2

2 3 4 5 6 ... N

and so on?

Or something else.. the main goal is just to hide every single page number.

 <?php
     if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
     $start_from = ($page-1) * 10;
     $result = $pdo->prepare("SELECT t.* FROM images t order by randorder ASC LIMIT $start_from, 10");
     $result->execute();

     for($i=0; $row = $result->fetch(); $i++)
     {                                      
            echo 'echo data';
     }

    echo '<div class="pagination" >';

        $result = $pdo->prepare("SELECT COUNT(image_id) FROM images");
        $result->execute();
        $row = $result->fetch();
        $total_records = $row[0];
        $total_pages = ceil($total_records / 10);

        for ($i=1; $i<=$total_pages; $i++) {
            echo "<a href='?page=".$i."'";
            if($page==$i)
            {
                echo "class=active";
            }
                echo ">";
                echo "".$i."</a> ";
        };
        echo '</div>'; 
?>  
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 关于#python#的问题:自动化测试