total_record = intval($total); $this->pagesize = intval($pagesize); $this->cur_page = intval($cur_page); $this->_count(); } private function _count() //计算 { if($this->total_record <= 0 || $this->pagesize <= 0){ $this->total_record = 0; $this->pagesize = 0; $this->total_pages = 0; $this->cur_page = 0; $this->offset = 0; return; } $this->total_pages = ceil($this->total_record / $this->pagesize); if($this->cur_page < 1 || $this->cur_page > $this->total_pages ){ $this->cur_page = 1; } $this->offset = ($this->cur_page - 1) * $this->pagesize; } //html数字连接的标签 public function num_link($url) { if($this->total_pages == 0){ return ''; } if($this->total_pages == 1){ return ''; } $start = floor(($this->cur_page - 1) / $this->_pernum) * $this->_pernum + 1; $end = $start + $this->_pernum; $text[] = '共有 ' . $this->total_record . '条记录 | 当前' .$this->cur_page."/". $this->total_pages . '页'; if($this->total_pages > $this->_pernum){ if( $this->cur_page != 1){ $text[] = "[首页]"; } else { $text[] = '[首页]'; } $up = $start - $this->_pernum; if( $up > 0 ){ $text[] = "[]"; } else { $text[] = '[]'; } } for($i = $start;$i<$end&&$i<=$this->total_pages;$i++){ if($i != $this->cur_page){ $text[] = "$i"; } else { $text[] = "$i"; } } if($this->total_pages > $this->_pernum){ $down = $this->total_pages - $end; if($down >= 0){ $text[] = "[]"; } else { $text[] = '[]'; } if($this->cur_page != $this->total_pages){ $text[] = "[尾页]"; } else { $text[] = '[尾页]'; } } return implode(' ',$text); } /** * @param $maxpage 总页数 * @param $page 当前页 * @param string $para 翻页参数(不需要写$page),如http://www.example.com/article.php?page=3&id=1,$para参数就应该设为'&id=1' * @return string 返回的输出分页html内容 */ function multipage($url,$total, $page,$pagesize,$start, $para = '') { $maxpage = ceil($total/$pagesize); $end = $start+$pagesize; $start = $start+1; if($end >= $total){ $end = $total; } $multipage = ''; //输出的分页内容 $listnum = 5; //同时显示的最多可点击页面 if ($maxpage < 2) { return ''; }else{ $offset = 2; if ($maxpage <= $listnum) { $from = 1; $to = $maxpage; } else { $from = $page - $offset; //起始页 $to = $from + $listnum - 1; //终止页 if($from < 1) { $to = $page + 1 - $from; $from = 1; if($to - $from < $listnum) { $to = $listnum; } } elseif($to > $maxpage) { $from = $maxpage - $listnum + 1; $to = $maxpage; } } $multipage .= ($page - $offset > 1 && $maxpage >= $page ? "
  • 首页
  • " : ''). ($page > 1 ? "
  • 上一页
  • ' : ''); for($i = $from; $i <= $to; $i++) { $multipage .= ($i == $page|| ($i == 1 && !$page)) ? "
  • '.$i.'
  • ' : "
  • '.$i. '
  • '; } $page = $page==0?1:$page; $multipage .= ($page < $maxpage ? "
  • 下一页
  • ' : ''). ($to < $maxpage ? "
  • 尾页
  • ' : ''); $multipage = $multipage ? '
    显示'.$start.'到'.$end.',共'.$total.'条
    ' : ''; } return $multipage; } } ?>