欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2024-02-07 13:18:46
...
类 php class function
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_pagecurrent_page=1;        }        if($this->current_pagecurrent_page=0;        }        $total_page_size = ceil($total_record/$page_size);        if($this->total_page_sizetotal_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_startpage_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 "page_replace(1)."  \" title=\" 首页 \">首页\n";    	}    	else{    		return "首页";    	}    }    //上一页    private function page_up(){    	if($this->current_page != 1){    		return "page_replace($this->current_page-1)."  \" title=\"上一页\">上一页\n  ";    	}    	else{    		return "上一页";    	}    }    //下一页    private function page_down(){    	if($this->current_page!=$this->total_page_size){    		return  "page_replace($this->current_page+1)."  \" title=\"下一页\">下一页 \n";    	}    	else{    		return "下一页";    	}    }    //尾页    private function page_end(){    	if($this->current_page!=$this->total_page_size){    		return "page_replace($this->total_page_size)." \" title=\"尾页\">尾页";    	}    }   public function output($id='page'){   	$str = "
共有 "; $str.= "$this->total_record"."条/".$this->current_page."页 "; $str.= $this->page_up();//调用方法显示上一页 //以下显示 分页 for($page_for_i=$this->page_start;$page_for_i page_stop; $page_for_i++){ if($this->current_page==$page_for_i){ $str.=" $page_for_i "; }else{ $str.=" page_replace($page_for_i). \" title=\"第".$page_for_i."页\" "; $str.=$page_for_i.""; } } $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);