> 백엔드 개발 > PHP 튜토리얼 > 新手提问分页类的一个输出循环显示分页遇到问题,求解?

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

WBOY
풀어 주다: 2016-06-23 14:21:23
원래의
790명이 탐색했습니다.

类 php class function

<?phpclass 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={page}');echo $page -> output();//显示?>
로그인 후 복사


为什么在其他成员函数里echo $this->page_stop的值是1啊?但在构造函数里为5 导致  output的for循环总是输出1   我想循环显示  哪里错误了?  

回复讨论(解决方案)

24 行的
$total_page_size = ceil($total_record/$page_size);
应改为
$ this->total_page_size = ceil($total_record/$page_size);

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿