/**** php mysql ページング クラス* http://bbs.it-home.org の編成*/class Pagination{ private $_result; private $_count; //记录数 private $_pageMax; //最大页 private $_page; //当前页 private $_url; private $_startPage;//分页条起請 private $_endPage; // 分页条止码 private $_nextPage; //上一页 private $_prePage; //下一页 function __construct($table, $pageSize, $getPage){ $this->_result = $GLOBALS['db']->query('SELECT * FROM '.$table); $this->_count = $GLOBALS['db']->getRecordNum(); $this->_pageMax = ceil($this->_count/$pageSize); $this->_result = ''; p> if($_GET[$getPage] == '') $this->_page = 1; else $this->_page= max(intval($_GET[$getPage]), 1); $this->_page = min($this->_page, $this->_pageMax); $offset = ($this->_page - 1) * $pageSize; $sql = 'SELECT * FROM '.$table.'リミット』。 $オフセット .','。 $pageSize; $this->_result = $GLOBALS['db']->query($sql); } function getRecord(){ return $GLOBALS['db']->getRecord( ); } function getPageBar($url = '?', $barLn = 10, $style = 1){ if($style == 1){ if($barLn % 2 != 0 ){ $midder = ceil($barLn / 2); $big_repair = $midder - 1 ;//当上面以进一法取整,则这里為减1,反之是加1 }else{ $midder = $ big_repair = $barLn / 2; } $sml_repair = $midder- 1; $this->_startPage = ($this->_page + $midder) > $this->_pageMax ? $this->pageMax - $barLn : $this->_page - $sml_repair; $this->_endPage = $this->_page < $真ん中? $barLn : $this->_page + $big_repair; }elseif($style == 2){ if($this->_page % $barLn == 0 ){ $this->_startPage = $this->_page; }else{ $this->_startPage = ($this->_page > $barLn)? $this->_page - ($this->_page % $barLn ) : 1; } $this->_endPage = $this->_startPage + $barLn - 1; } $this-> ;_url = $url; $this->_nextPage = $this->_page + 1; $this->_prePage = $this->>_page - 1; $this->_startPage = max( $this->_startPage, 1);//少なくとも最初页开始 $this->_endPage = min($this->_endPage, $this->_pageMax);//最もただ末页 $this->_result = '当前是:'.$this->_page.'/'.$this->_pageMax. '页,共'.$this->_count.'条记录'; if ($this->_page > 1) $ this->_result .= ' 9 '; else $this->_result .= '9 3 for($i = $this->_startPage; $i <= $this->_endPage; $i++) { if ($this->_page == $i) $this-> _result .= ''.$i.''; else $this->_result.= ''.$i.''; } if ($this->_page != $this->_pageMax) { $this->_result .= '4'; $this->_result .= ':< /a>'; } else { $this->_result.= '4:'; } $this->_result.= ' function ChickForm(){ var submit = true; var page_num =document.getElementById("page").value; var exp=/^d*$/; var objExp=new RegExp(exp); if(page_num==""){ alert(" はできません空"); submit = false; }else if(!objExp.test(page_num)){ alert("得是数字"); submit = false; } return submit; } script> '; return $this->_result; } } ?> 复制代网 2、调用例 $page = new Pagination($table, 5, 'page');while($row = $page->getRecord()){ echo $row[0] ,''; } echo $page->getPageBar('?',8, 1); ?> 复制發