page_total_rows - 每页展示数量 默认值20
$total_rows - 总计数据条目数
$totpages - 总页数计算
$pages_current - 当前页面
利用url参数传递 当前页码 url参数名称 pages
$style - 页码展示样式可以通过外部访问样式属性进行修改
***********************使用方法**********************
调用该类:$pages = new pages;
调用该类后请修改数据集总条数
$pages->total_rows = $totrows;
$pages->main();方法将返回limit需要的2个参数 关联数组的a,b2个元素
$limit = $pages->main();
通过访问不同方法即可展示不同的功能!
PHP远程分页类实例代码如下:
- <?php
- class pages{
- public $page_total_rows = 20;
- public $total_rows;
- public $totpages;
- public $current_url;
- private $ask;
- public $style ='<style type="text/css教程">
- .pages_norename{width:50px; height:20px; float:left; background-color:#e3eff3; margin-right:5px; text-align:center; line-height:20px; border:1px solid #333333;}
- .pages_norename a{display:block; width:50px; height:20px; color:#333333; text-decoration:none;}
- .pages_norename a:hover{background-color:#ff9900; color:#ffffff;}
- .pages_nore_more{width:auto; height:20px; float:left; margin-right:5px; line-height:20px; background-color:#e3eff3; border:1px solid #333333;}
- .pages_nore_more a{display:block; width:20px; height:20px; color:#333333; text-decoration:none; text-align:center;}
- .pages_nore_more a:hover{background-color:#ff9900; color:#ffffff;}
- .pages_se{width:auto; height:20px; float:left;}
- .pages_se select{margin:0px; padding:0px; font-family:arial, helvetica, sans-serif; font-size:12px;}
- </style>
- ';
-
- function main(){
- $this->totpages = ceil($this->total_rows/$this->page_total_rows);
-
- if(!isset($_get['pages']))
- {
- $this->pages_current = 1;
- }else
- {
- $this->pages_current = intval($_get['pages']);
-
- if($this->pages_current < 1){
- $this->pages_current = 1;
- }
-
- if($this->pages_current > $this->totpages){
- $this->pages_current = $this->totpages;
- }
-
- if(isset($_get['pages'])){unset($_get['pages']);}
- if(isset($_get['total_rows'])){unset($_get['total_rows']);}
-
- }
-
- $limit['a'] = $start = ($this->pages_current - 1)*$this->page_total_rows;
- $limit['b'] = $this->page_total_rows;
-
- $urlin = explode('/',$_server['php教程_self']);
-
- $tot_url = sizeof($urlin);
- $this->current_url =$urlin[$tot_url-1];
-
- if(sizeof($_get) > 0){
- foreach($_get as $key=>$values){
- $urlsget .= $key.'='.$values.'&';
- }
- $this->current_url .= '?'.$urlsget;
- $this->ask = '';
- }else{$this->ask = '?';}
-
- echo $this->style;
- return $limit;
- }
-
-
- function firstpage(){
- echo '<div class="pages_norename"><a href="'.$this->current_url.'">首页</a></div>';
- }
-
- function prepage(){
- echo '<div class="pages_norename"><a href="'.$this->current_url.$this->ask.'pages='.($this->pages_current-1).'">上一页</a></div>';
- }
-
- function nextpage(){
- echo '<div class="pages_norename"><a href="'.$this->current_url.$this->ask.'pages='.($this->pages_current+1).'">下一页</a></div>';
- }
-
- function lastpage(){
- echo '<div class="pages_norename"><a href="'.$this->current_url.$this->ask.'pages='.($this->totpages).'">尾页</a></div>';
- }
-
- function morepage(){
- if($this->pages_current == 1){$newtj = $this->pages_current+9;}
- elseif($this->pages_current == 2){$newtj = $this->pages_current+8;}
- elseif($this->pages_current == 3){$newtj = $this->pages_current+7;}
- else{$newtj = $this->pages_current+6;}
- for($i=$this->pages_current-3;$i<=$newtj;$i++){
- if($i==$this->pages_current){$strong ='<strong>'; $strong2 ='</strong>';}else{$strong='';$strong2='';}
- if($i >=1){echo '<div class="pages_nore_more"><a href="'.$this->current_url.$this->ask.'pages='.$i.'">'.$strong.$i.$strong2.'</a></div>';}
- if($i >= $this->totpages){
- break;
- }
- }
- }
-
- function changepage(){
- echo '<div class="pages_se"><select name="dd">';
- for($i=1;$i<=$this->totpages;$i++){
- if($this->pages_current == $i){$selected = ' selected="selected"';}else{$selected = '';}
- echo '<option value="'.$i.'"'.$selected.'>第'.$i.'页</option>';
- }
- echo '</select></div>';
- }
- }
- ?>
该类可以自动识别 url 参数,避免了一般分页类丢失url参数问题,样式可以通过style属性进行修改,提供 首页 上一页 下一页 尾页 中间 过渡页 跳转菜单功能. |