首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

新手提问分页类的一个输出循环显示分页遇到有关问题,求解

2013-09-09 
新手提问分页类的一个输出循环显示分页遇到问题,求解??phpclass PageClass {private $total_record//总

新手提问分页类的一个输出循环显示分页遇到问题,求解?


<?php
class PageClass {
private $total_record;//总记录
private $page_size;//页记录数
private $current_page;//当前页
private $total_page_size;//总页数
private $page_url;   //页面url
private $page_start;  //起始页
private $page_stop;//结束页
public $page_limit;  //limit,
    function __construct($total_record=0,$page_size=1,$current_page=1,$page_url) {
    $this->total_record=$this->numeric($total_record);
    $this->page_size=$this->numeric($page_size);
    $this->current_page=$this->numeric($current_page);
    $this->page_limit=($this->current_page*$this->page_size)-$this->page_size;
        $this->page_url=$page_url;
        if($this->current_page<1){
        $this->current_page=1;
        }

        if($this->current_page<0){
        $this->current_page=0;
        }
        $total_page_size = ceil($total_record/$page_size);

        if($this->total_page_size<1){
        $this->total_page_size=1;
        }
        if($this->current_page>$this->total_page_size){
        $this->crrent_page=$this->total_page_size;
        }
        $this->page_start=$this->current_page;
        $this->page_stop=$this->current_page+5;
        if($this->page_stop>$this->total_page_size){
        $this->page_stop=$this->total_page_size;
        $this->page_start=$this->page_stop-5;
        }
        if($this->page_start<1){
        $this->page_start=1;
        if($this->page_stop > $this->total_page_size){
        $this->page_stop=$this->total_page_size;
        }


        }
    }

    private function numeric($id){
        if(strlen($id)){
        if(!ereg("^[0-9]+$",$id)){ 
         $id=1;
        }
        }
        else{
        $id=1;
        }
        return $id;
    }


    private function page_replace($page){
    return str_replace("{page}",$page,$this->page_url);
    }
    //首页
    private function home(){
    if($this->current_page!=1){
    return "<a href=" ".$this->page_replace(1)."  " title=" 首页 ">首页</a>\n";
    }
    else{
    return "首页";
    }
    }
    //上一页
    private function page_up(){
    if($this->current_page != 1){
    return "<a class="number" href=" ".$this->page_replace($this->current_page-1)."  " title="上一页">上一页</a>\n  ";
    }
    else{
    return "<a class="number">上一页</a>";
    }
    }
    //下一页
    private function page_down(){
    if($this->current_page!=$this->total_page_size){
    return  "<a class="number" class='nolink nextpage' href= "  ".$this->page_replace($this->current_page+1)."  " title="下一页">下一页</a> \n";
    }
    else{
    return "<a class="number" class='nolink nextpage'>下一页</a>";
    }
    }
    //尾页
    private function page_end(){
    if($this->current_page!=$this->total_page_size){
    return "<a href=" ".$this->page_replace($this->total_page_size)." " title="尾页">尾页</a>";


    }
    }


   public function output($id='page'){
   $str = "<form action='' name='formpage' method=post><a>共有 ";
   $str.= "<B>$this->total_record"."条/".$this->current_page."页</B> </a>";
   $str.= $this->page_up();//调用方法显示上一页

   //以下显示  分页
        for($page_for_i=$this->page_start;$page_for_i <= $this->page_stop;  $page_for_i++){
   if($this->current_page==$page_for_i){
   $str.=" <a class="number current">$page_for_i</a> ";
   }else{
   $str.=" <a href="  .$this->page_replace($page_for_i). " title="第".$page_for_i."页" ";
   $str.=$page_for_i."</a>";
   }
   }

   $str.=$this->page_down();  //调用下一页
   return $str;
   }

}
$page = new PageClass(1000,5,$_GET,'?page={page}');
echo $page -> output();//显示
?>



为什么在其他成员函数里echo $this->page_stop的值是1啊?但在构造函数里为5 导致  output的for循环总是输出1   我想循环显示  哪里错误了?  
类 php class function
[解决办法]
24 行的
$total_page_size = ceil($total_record/$page_size);
应改为
$this->total_page_size = ceil($total_record/$page_size);

热点排行