php分页类-创新互联
total_rows = $total;
$this->onepage_rows = $onepage_rows;
$this->page_rows = $page_rows;
$this->total_page = ceil($this->total_rows / $this->onepage_rows);
$this->self_page = min(max((int)@$_GET['page'],1),$this->total_page);
$this->start_id= ($this->self_page-1)*$this->onepage_rows+1;
$this->end_id= min($this->self_page*$this->onepage_rows , $this->total_rows);
$this->desc = $this->desc($desc); //上一页 下一页 共X条记录等信息
$this->url = $this->requestUrl(); //URL生成
}
private function requestUrl(){
$url =isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'] ;
$parse_url = parse_url($url);
if(isset($parse_url['query'])){
parse_str($parse_url['query'],$arr);
unset($arr['page']);
$url = $parse_url['path'] .'?'.http_build_query($arr).'&page=';
}else{
$url = strstr($url,'?') ? $url.'page=' :$url. '?page=';
}
return $url;
}
//指定列表页码
public function pagelist(){
$start=max(1,min($this->self_page-ceil($this->page_rows/2),$this->total_page-$this->page_rows));
$end=$start + $this->page_rows;
$arr = array();
for($i=$start; $i<=$end; $i++){
if($i == $this->self_page){
$arr[$i]['url'] = '';
$arr[$i]['str'] = $i;
continue;
}
$arr[$i]['url'] = $this->url.$i;
$arr[$i]['str'] = $i;
}
return $arr;
}
//返回代码列表的字符串表示
public function pageshow(){
$pagelist = $this->pagelist();
$pagestr = '';
foreach($pagelist as $v){
if(empty($v['url'])){
$pagestr .= ''.$v['str'].'';
continue;
}
$pagestr .= "".$v['str']."";
}
return $pagestr;
}
public function desc($desc){
$d = array('prev' => '上一页','next' => '下一页','first'=> '首页','last' => '末页');
if(empty($desc) || !is_array($desc)){ return $d;}
function filter($v){
return !empty($v);
}
return array_merge($d,array_filter($desc,'filter'));
}
//首页
public function first(){
return $this->self_page > 1 ? 'url.'1">'.$this->desc['first'].'':'';
}
//末页
public function last(){
return $this->self_page < $this->page_rows ? 'url.$this->page_rows.'">'.$this->desc['last'].'':'';
}
//上一页
public function prev(){
return $this->self_page > 1 ? 'url.($this->self_page-1).'">'.$this->desc['prev'].'':'';
}
//下一页
public function next(){
return $this->self_page < $this->total_page ? 'url.($this->self_page+1).'">'.$this->desc['next'].'':'';
}
//返回当前第X-X条
public function nowpage(){
return '当前第'.$this->self_page.'页 第'.$this->start_id.'——'.$this->end_id.'条';
}
public function limit(){
return 'limit '.max(0,($this->self_page-1)*$this->onepage_rows).','.$this->onepage_rows;
}
}
?>网站设计制作过程拒绝使用模板建站;使用PHP+MYSQL原生开发可交付网站源代码;符合网站优化排名的后台管理系统;成都网站设计、网站建设、外贸网站建设收费合理;免费进行网站备案等企业网站建设一条龙服务.我们是一家持续稳定运营了十载的创新互联建站网站建设公司。
网页标题:php分页类-创新互联
网站地址:http://myzitong.com/article/isgcg.html
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页标题:php分页类-创新互联
网站地址:http://myzitong.com/article/isgcg.html