Home > Backend Development > PHP Tutorial > mysqli - PHP+mysql分页问题

mysqli - PHP+mysql分页问题

WBOY
Release: 2016-06-06 20:39:33
Original
932 people have browsed it

mysqli - PHP+mysql分页问题

求教一下,PHP+Mysql怎么实现图示分页?

回复内容:

mysqli - PHP+mysql分页问题

求教一下,PHP+Mysql怎么实现图示分页?

cc http://www.v2ex.com/t/158755

分页导航链接可以这样写:
mysqli - PHP+mysql分页问题

<code><?php header('Content-Type: text/html;charset=utf-8');
$page = (!empty($_GET['p'])) ? intval($_GET['p']) : 1;
page($page);

function page($page=1, $page_size=10){
    $total_records = 505;
    $total_pagas = ceil($total_records/$page_size);
    echo '页数: '.$total_pagas.'<br />';
    if($total_pagas==0){
        echo '<b>查询结果为空</b><br>'; 
    }else if($page>$total_pagas || $page 
        <a href="page.php?p=1">最前</a><br>
        <a href="page.php?p=<?php%20echo%20%24total_pagas;%20?>">最后</a><br>
        <?php echo '<b>第1页(没有该页,统一显示第一页)<br>';
        $page = 1;
        if($total_pagas>=$page+4){
            for($i=$page+1;$i
                <a href="page.php?p=<?php%20echo%20%24i;%20?>">第<?php echo $i; ?>页</a><br>
                <?php }
            if($page!=$total_pagas){
                ?>
                <a href="page.php?p=<?php%20echo%20%24page+1;%20?>">下一页</a><br>
                <?php }
        }else{
            for($i=$page+1;$i<=$total_pagas;$i++){
                //echo $i;
                ?>
                <a href="page.php?p=<?php%20echo%20%24i;%20?>">第<?php echo $i; ?>页</a><br>
                <?php }
            if($page!=$total_pagas){
                ?>
                <a href="page.php?p=<?php%20echo%20%24page+1;%20?>">下一页</a><br>
                <?php }
        }
    }else{
        ?>
        <a href="page.php?p=1">最前</a><br>
        <a href="page.php?p=<?php%20echo%20%24total_pagas;%20?>">最后</a><br>
        <?php //前输出5页,后输出4页.
        if($page<=5){
            if($page!=1){
                ?>
                <a href="page.php?p=<?php%20echo%20%24page-1;%20?>">上一页</a><br>
                <?php }
            for($i=1;$i<$page;$i++){
                //echo $i;
                ?>
                <a href="page.php?p=<?php%20echo%20%24i;%20?>">第<?php echo $i; ?>页</a><br>
                <?php }
        }else{
            if($page!=1){
                ?>
                <a href="page.php?p=<?php%20echo%20%24page-1;%20?>">上一页</a><br>
                <?php }
            for($i=$page-5;$i<$page;$i++){
                //echo $i;
                ?>
                <a href="page.php?p=<?php%20echo%20%24i;%20?>">第<?php echo $i; ?>页</a><br>
                <?php }
        }
        echo '<b>第'.$page.'页(当前页)<br>';
        if($total_pagas>=$page+4){
            for($i=$page+1;$i
                <a href="page.php?p=<?php%20echo%20%24i;%20?>">第<?php echo $i; ?>页</a><br>
                <?php }
            if($page!=$total_pagas){
                ?>
                <a href="page.php?p=<?php%20echo%20%24page+1;%20?>">下一页</a><br>
                <?php }
        }else{
            for($i=$page+1;$i<=$total_pagas;$i++){
                //echo $i;
                ?>
                <a href="page.php?p=<?php%20echo%20%24i;%20?>">第<?php echo $i; ?>页</a><br>
                <?php }
            if($page!=$total_pagas){
                ?>
                <a href="page.php?p=<?php%20echo%20%24page+1;%20?>">下一页</a><br>
                <?php }
        }
    }
}
?>

?>
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template