新做的一個類,比較實用~~樣式如下:
|<< << 1 2 3 4 5 6 7 8 >> >>|
大家覺得有用可以帶走~~呵呵……
<?php /*************************** * 一個非常實用個性的分頁類 * **************************** *****************************實例*********************************** if(!isset($_GET['page'])){$page = 0;}else{$page = $_GET['page'];} $pagedemo = new pageclass; $pagedemo->set_sql("SELECT * FROM `demo` ORDER BY `id` DESC"); $pagedemo->set_params("type=".$type.""); $pagedemo->set_setpage($page); $pagedemo->set_pagesize(10); $pagedemo->set_filename("demo.php"); $pagedemo->set_pagenumber(5); $pagedemo->show(); $result=$pagedemo->result; $n=0; while ($row=mysql_fetch_row($result)){ $n++; echo "內(nèi)容"; } $pagedemo->showpage(); *******************************************************************/ class pageclass { /****聲明****/ var $sqlstr,$filename,$params,$initfirstpage; var $pagestart,$pagenumber,$pagesize,$i; var $firstpage,$prevpage,$nextpage,$lastpage; var $totallines,$maxpage,$totalpages,$result; var $page,$final,$getpage,$param,$paramlist; /****構造函數(shù)****/ function pageclass() { $this->set_initfirstpage("僅此一頁"); // 設置只有一頁時顯示的文字,; $this->set_setpage(0); // 設置默認第一頁為0,; $this->set_pagesize(10); // 設置默認記錄數(shù)為10; $this->set_params(""); // 設置默認參數(shù)列表為空,; $this->set_pagestart(0); // 設置默認分頁起始數(shù)為0,; $this->set_pagenumber(5); // 設置默認每頁顯示頁數(shù)為5; $this->set_firstpage("|<<"); // 設置默認上N頁表示字符為|<<,; $this->set_prevpage("<<"); // 設置默認上一頁表示字符為<<; $this->set_nextpage(">>"); // 設置默認下一頁表示字符為>>; $this->set_lastpage(">>|"); // 設置默認下N頁表示字符為>>|; } /*****設置SQL查詢語句****/ function set_sql($sqlstr) { $this->sqlstr = $sqlstr; } /****設置每頁顯示記錄數(shù)****/ function set_pagesize($pagesize) { $this->pagesize = $pagesize; } /****設置文件名稱****/ function set_filename($filename) { $this->filename = $filename; } /****設置參數(shù)列表(可設多項)****/ function set_params($params) { $this->params = $params; } /****設置頁面開始數(shù)(默認為0)****/ function set_pagestart($pagestart) { $this->pagestart = $pagestart; } /****設置每頁顯示頁數(shù)****/ function set_pagenumber($pagenumber) { $this->pagenumber = $pagenumber; } /****設置首頁圖標或字符****/ function set_firstpage($firstpage) { $this->firstpage = $firstpage; } /****設置上一頁圖標或字符****/ function set_prevpage($prevpage) { $this->prevpage = $prevpage; } /****設置下一頁圖標或字符****/ function set_nextpage($nextpage) { $this->nextpage = $nextpage; } /****設置末頁圖標或字符****/ function set_lastpage($lastpage) { $this->lastpage = $lastpage; } /****設置總頁數(shù)為一頁時顯示的文字****/ function set_initfirstpage($initfirstpage) { $this->initfirstpage = $initfirstpage; } /****取得當前頁數(shù)****/ function set_setpage($getpage) { $this->getpage = $getpage; } /****取出數(shù)據(jù)集****/ function show() { $this->final = ''; $this->param = preg_replace("/&?page=[0-9]*&?/", '', $this->params); $this->totallines = mysql_num_rows(mysql_query($this->sqlstr)); if(isset($this->totallines)) { $this->totalpages = ceil($this->totallines / $this->pagesize); }else{ $this->totalpages = 1; } $this->result = mysql_query($this->sqlstr." limit ".$this->getpage * $this->pagesize .", ". $this->pagesize); } /****顯示分頁****/ function showpage() { if($this->totalpages > $this->pagenumber && $this->getpage > $this->pagenumber - 1) { $this->paramlist = '?page='.($this->getpage - $this->pagenumber); $this->paramlist .= "&".$this->param; $this->final .= "<a href=./".$this->filename.$this->paramlist.">".$this->firstpage."</a> "; $this->pagestart = intval($this->getpage / $this->pagenumber) * $this->pagenumber; }else $this->final .= $this->firstpage." "; if($this->getpage) { $this->paramlist = '?page='.($this->getpage - 1); $this->paramlist .= "&".$this->param; $this->final .= "<a href=./".$this->filename.$this->paramlist.">".$this->prevpage."</a> "; } else $this->final .= $this->prevpage." "; if($this->totalpages < $this->pagenumber) { $this->maxpage = $this->totalpages; }else{ $this->maxpage = $this->pagenumber; } for($this->i = $this->pagestart, $this->paramlist = '', $this->maxpage += $this->pagestart; $this->i < $this->maxpage; $this->i ++) { $this->paramlist .= '?page='.$this->i; $this->paramlist .= "&".$this->param; if($this->i != $this->getpage) { $this->final .= "<a href=./".$this->filename.$this->paramlist.">".($this->i + 1).'</a> '; }else{ $this->final .= "<a href=./".$this->filename.$this->paramlist."><strong>".($this->i + 1).'</strong></a> '; } $this->paramlist = ''; } if((++ $this->getpage)< $this->totalpages) { $this->paramlist = "?page=".$this->getpage; $this->paramlist .= "&".$this->param; $this->final .= "<a href=./".$this->filename.$this->paramlist.">".$this->nextpage."</a> "; } else $this->final .= " ".$this->nextpage; $this->getpage --; if(($this->getpage + $this->pagenumber) < $this->totalpages) { $this->paramlist = '?page='.($this->getpage + $this->pagenumber); $this->paramlist .= "&".$this->param; $this->final .= " <a href=./".$this->filename.$this->paramlist.">".$this->lastpage."</a>"; } else $this->final .= " ".$this->lastpage; if($this->maxpage == 1) $this->final = $this->initfirstpage; print $this->final; } } ?>
|