如何在页面底部显示分页?


How to show paging at the bottom of the page ??

我用php创建了一个数据网格,并且我计算了每页10条记录中显示的表和数据网格的记录计数。

我的问题是分页显示在数据网格的底部。如果记录计数增加,则不显示底部div 中的页数。

如果我的记录为 1000 条,每页将显示 10

条记录,则页数将为 100。

<?php for($i=1;$i<=$page_count;$i++) { ?>
<li><a><?php print("$i"); ?></a></li>
<?php } ?>

显示此顶部代码:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...100

我希望如果用户单击第 12 页,第 1 页到 9 页将不会显示:

你可以尝试这样的事情:

您必须设置$numberItems项目总数,$firstElementDisplayed显示的当前元素的索引,$itemsPerPage每页显示的项目数,$showeachside要显示所选页面两侧的页面数

<?php
    $numberItems = 20; // Number of items;
    $firstElementDisplayed = 3; // Current start element position
    $itemsPerPage = 2; // Number of items showed per page
    $showeachside = 3; //  Number of page displayed either side of selected page
    if(empty($firstElementDisplayed))$firstElementDisplayed=0;  // Current start element position
    $page_count = ceil($numberItems / $itemsPerPage); // Number of pages
    $currentPage = ceil($firstElementDisplayed / $itemsPerPage); // Current page
?>
<?php
if(($firstElementDisplayed-$itemsPerPage) >= 0) //We are not on the first page => << is displayed
{
?>
<a href="#urlFirstPage"><<</a> 
<?php
}
?>
<?php 
$eitherside = ($showeachside * $itemsPerPage);
if($firstElementDisplayed+1 > $eitherside) echo " .... ";
$page=1;
for($y=0;$y<$numberItems;$y+=$itemsPerPage)
{
    $class=($y==$firstElementDisplayed)?"pageselected":"";
    if(($y > ($firstElementDisplayed - $eitherside)) && ($y < ($firstElementDisplayed + $eitherside)))
    {
        ?>
        <a class="<?php print($class);?>" href="#urlPage"><?php print($page);?></a>
        <?php
    }
    $page++;
}
if(($firstElementDisplayed+$eitherside)<$numberItems)print (" .... ");
?>
<?php 
if($firstElementDisplayed+$itemsPerPage<$numberItems) //We are not on the last page => >> is displayed
{
?>
<a href="#urlLastPage">>></a> 
<?php
}
?>
Page <?php print($currentPage);?> of <?php print($page_count);?>