您当前的位置:首页 > 计算机 > 编程开发 > PHP

PHP 简单分页代码

时间:02-20来源:作者:点击数:

PHP 简单分页代码

total_page     = 10;
$current_page   = empty($_GET['page']) ? 1 : $_GET['page'];
$previous_page  = $current_page - 1;
$next_page      = $current_page + 1;
 
if ($previous_page == 0) {
    $previous_page = 1;
}
 
 
if ($next_page > $total_page) {
    $next_page = $current_page;
}
 
echo "<a href='test.php?page=1'> First Page </a>";
echo "<a href='test.php?page=$previous_page'> Previous </a>";
 
for ($i=1; $i < $total_page; $i++) :
    if ($current_page == $i) {
        echo "<a href='test.php?page=$i'> $i - Selected </a>";
    }else{
        echo "<a href='test.php?page=$i'> $i </a>";
    }
 
endfor;
 
echo "<a href='test.php?page=$total_page'> Last Page </a>";
echo "<a href='test.php?page=$next_page'> Next </a>";

 

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门