首页 > php教程 > php手册 > php 分页函数

php 分页函数

WBOY
发布: 2016-05-25 16:57:30
原创
999 人浏览过
 代码如下 复制代码
class ajaxpage{
var $result;
 var $anchors;
 var $total;
 var $db;
 var $网页特效p/jsp.html target=_blank >jsp教程agination;
 function __construct($qry,$starting,$recpage,$jspagination)
 {  
     $this->db   =   &$globals['db'];
  $this->jspagination =  $jspagination;
  $rst  = $this->db->query($qry);
  $numrows = $this->db->num_rows;
  $qry   .= " limit $starting, $recpage";
  
  $this->result = $this->db->get_results($qry,array_a);
  
  $next  = $starting+$recpage;//the number next time end
  //$var  = ((intval($numrows/$recpage))-1)*$recpage;
  $page_showing = intval($starting/$recpage)+1;//the str shows on the page bar
  $total_page = ceil($numrows/$recpage); //total page
  if($numrows % $recpage != 0){
   $last = ((intval($numrows/$recpage)))*$recpage;
  }else{
   $last = ((intval($numrows/$recpage))-1)*$recpage;
  }
  $previous = $starting-$recpage;
  $anc = "
    ";
      if($previous    $anc .= "
  • first
  • ";
       $anc .= "
  • previous
  • ";
      }else{
       $anc .= "";
       $anc .= "";
      }
      
      ################if you dont want the numbers just comment this block############### 
      
      $norepeat = 3;//no of pages showing in the left and right side of the current page in the anchors
      $j = 1;
      $anch = "";
      for($i=$page_showing; $i>1; $i--){
       $fpreviouspage = $i-1;
       $page = ceil($fpreviouspage*$recpage)-$recpage;
       $anch = "
  • $fpreviouspage
  • ".$anch;
       if($j == $norepeat) break;
       $j++;
      }
      $anc .= $anch;
      $anc .= "
  • ".$page_showing."
  • ";
      $j = 1;
      for($i=$page_showing; $i   $fnextpage = $i+1;
       $page = ceil($fnextpage*$recpage)-$recpage;
       $anc .= "
  • $fnextpage
  • ";
       if($j==$norepeat) break;
       $j++;
      }
      
      ############################################################
      if($next >= $numrows){
       $anc .= "
  • next
  • ";
       $anc .= "
  • last
  • ";
      }else{
       $anc .= "";
       $anc .= "";
      }
       $anc .= "
";
  $this->anchors = $anc;
  
  $this->totalstr = "page : $page_showing of  $total_page . total records found: $numrows";
 }
}



永久地址:

转载随意~请带上教程地址吧^^

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板