zoukankan      html  css  js  c++  java
  • php分页

    php分页源代码

    复制可用

    <?php
    
    //数据库请自行创建
    
    //连接数据库
    $conn=mysql_connect('localhost','root','');
    mysql_select_db('demo',$conn);
    mysql_query("set names utf8");
    error_reporting(0);
    
    $page_list=5; //每页显示条数
    $sqlcx1="select * from admin"; 
    $count=mysql_num_rows(mysql_query($sqlcx1)); //数据总条数
    $count_page=ceil($count/$page_list); //总页数
    $page=1; //第几页
    if($_GET['page']){
    $page=$_GET['page']; //超链接传递page变量
    }
    $offst=$page_list*($page-1); //页数跳转
    $sqlcx1="select * from admin limit $offst,$page_list"; //每页显示条数
    $result1=mysql_query($sqlcx1);
    
    //显示
    
    
    while ($row=mysql_fetch_array($result1)) {
    echo $row[1]."</br>";
    }
    
     
    
    //页码循环
    $b=10; //页尾数
    $a=1; //页始数
    $c=7; //页变数
    for($c; $c<=$count_page; $c++){ //总页数
    if($page>=$c){ //从第七页开始变化
    $b+=1;
    $a+=1;
    if($b>$count_page){ //限制总页数
    $b=$count_page;
    $a=$count_page-9;;
    }
    }
    }
    //输出分页
    for($a; $a<=$b; $a++){
    if($page==$a){
    $page_page.="<div style='background-color:#ccc;'>".$a."</div>";
    }else{
    $page_page.="<div><a href='?page=".$a."'>".$a."</a></div>";
    }
    
    }
    
     //end页码循环 
    
     
    
    //上页and下页
    if($page==$count_page){
    $next_page.="下一页";
    }else{
    $next_page.="<a href='?page=".($page+1)."'>下一页</a>";
    }
    
    if($page==1){
    $previous_page.="上一页";
    }else{
    $previous_page.="<a href='?page=".($page-1)."'>上一页</a>";
    }
    
    
    //首页
    if($page==1){
    $top_page.="首页";
    }else{
    $top_page.="<a href='?page=1'>首页</a>";
    }
    //尾页
    if($page==$count_page){
    $end_page.="尾页";
    }else{
    $end_page.="<a href='?page=$count_page'>尾页</a>";
    }
    
     
    
    //输出
    
    echo "第".$page_page."页";
    echo "</br>";
    echo $next_page;
    echo $previous_page;
    echo "</br>";
    echo $top_page;
    echo $end_page;
    ?>
    
    <html>
    <head>
    <style>
    div{float:left; border:1px solid #000; 15px; height:15px; text-align:center;}
    div:hover{background-color:#ccc;}
    a:hover{background-color:#ccc;}
    </style>
    </head>
    </html>
    

      

  • 相关阅读:
    Pascal's Triangle II
    Pascal's Triangle
    Best Time to Buy and Sell Stock II
    Best Time to Buy and Sell Stock
    Populating Next Right Pointers in Each Node
    path sum II
    Path Sum
    [转载]小波时频图
    [转载]小波时频图
    [转载]Hilbert变换及谱分析
  • 原文地址:https://www.cnblogs.com/fan-bk/p/6973592.html
Copyright © 2011-2022 走看看