发新话题
打印

用类实现翻页的整个程序

用类实现翻页的整个程序

0) { $current_page = min($total_pages,$current_page) ; }elseif ($current_page <0) { $current_page = max($current_page,-$total_pages); $current_page = $total_pages + $current_page +1; }else { $current_page = 1; } //if($total_pages ==0)$total_pages =1; $this->offset = ($total_pages ==0)?0:($current_page -1) * $page_size; $this->current_page=$current_page; $this->total_rows = $total_rows; $this->page_size = $page_size; $this->total_pages = $total_pages; } function reset() { $total_pages =&$this->total_pages; $current_page =&$this->current_page; $page_size = &$this->page_size; $total_rows = &$this ->total_rows; $total_pages = ceil($total_rows / $page_size); if ($current_page > 0) { $current_page = min($total_pages,$current_page) ; }elseif ($current_page <0) { $current_page = max($current_page,-$total_pages); $current_page = $total_pages + $current_page +1; }else { $current_page = 1; } $this ->offset = ($current_page -1) * $page_size; } function get_query() { $t=''; foreach($_GET as $k => $v) { if ($k!='page')$t .= sprintf('%s=%s&',$k,$v); } $this->get = $t; return($t); } function s_nav() { $total_pages =$this->total_pages; $current_page =$this->current_page; //$page_size = $this->page_size; //$total_rows = $this ->total_rows; if ($total_pages > 0) { $get = $this->get_query(); $j = ($current_page -$this->left)>0?$current_page -$this->left:1; $temp = ($current_page>1)?sprintf('第一页 上一页',$get,$get,$current_page-1):''; for($i = $j; $i < $current_page ;$i++ ) { $temp .= sprintf(' [%d]',$get,$i,$i) ; } $temp .= sprintf(' [%d]',$current_page); $j = ($current_page + $this -> right)>$total_pages?$total_pages:($current_page + $this -> right); for ($i = $current_page + 1 ;$i<= $j;$i++ ) { $temp .= sprintf(' [%d]',$get,$i,$i); } $temp .= ($current_page==$total_pages)?'':sprintf(' 下一页 最末页',$get,$current_page + 1,$get); $temp .= sprintf( ' %d/%d页 %d条记录',$this->current_page,$this->total_pages,$this->total_rows); }else{ $temp = '没有记录'; } return $temp; } } ?> //显示 s_nav(); ?>

TOP

发新话题