这个封装的分页函数怎么样改成这种效果呢?

WBOY
Release: 2016-06-20 12:37:31
Original
975 people have browsed it

不让它显示所有的页   永远只显示5页或者10页 就像图片中的一样    我这个代码应该怎么改呢?

function fenye(){
global $page,$pagenum;
echo "

";
echo "
    ";
    echo '
  • '.$page.'/'.$pagenum.'页|
  • ';
       if($page==1){
                 echo '
  • 首页|
  • ';
                 echo '
  • 上一页|
  • ';
       }else{
         echo '
  • 首页|
  • ';
                 echo '
  • 上一页|
  • ';
       }
       echo '
    ';
           echo '
      ';
             for($i=0;$i      echo '
    • '.($i+1).'
    • ';
           } 
             echo '
    ';
               echo '
    ';
       if($page==$pagenum){
        echo '
  • |下一页|
  • ';
        echo '
  • 尾页|
  • ';
       }else{
        echo '
  • |下一页|
  • ';
        echo '
  • 尾页|
  • ';
       }
    echo '
';
    echo '
';
    
};
?>


回复讨论(解决方案)

这是数据库查询的页面
   include 'fenye.php';
   header('content-type:text/html;charset=utf-8;');
   $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
   $stmt=$pdo->prepare("select * from jianzhi");
   $stmt->execute();
   $res=$stmt->fetchall();
   $rows=count($res);//总的条数
   $pagesize=8;//每页的条数
   if($rows==0){
    $pagenum=0;
   }else{
    $pagenum=ceil($rows/$pagesize);//分成几页
   }
   if(isset($_GET['page'])){
      $page=$_GET['page'];
      if(empty($page)||$page        $page=1;
      }else{
        $page=intval($page);
      } 
   }else{
    $page=1;
   }
   if($page>$pagenum){
    $page=$pagenum;
   }
   $startnum = ($page - 1)*$pagesize;
   $query = "SELECT * FROM blog LIMIT $startnum,$pagesize";
   $stmt2=$pdo->prepare($query);
   $stmt2->execute();
   $res2=$stmt2->fetchall(PDO::FETCH_ASSOC);

看看这个就明白了http://www.imooc.com/learn/419

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