- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- class PageList{
- private $link;
- private $result;
- private $maxline;
- private $page=1;
- private $startline=0;
- private $countline;
- public $countpage;
- private $prevpage;
- private $nextpage;
-
- private $dbhost=DBHOST;
- private $dbuser=DBUSER;
- private $dbpasswd=DBPASSWD;
- private $dbtable=DBTABLE;
-
-
-
-
-
-
-
-
-
-
-
-
-
- public function __construct($query,$maxline,$page){
- @$this->link=mysql_connect($dbhost,$dbuser,$dbpasswd) or die($this->feedback='System Error ,Please contect admin');
- @mysql_select_db($dbtable,$this->link) or die($this->feedback='System Error ,Please contect admin');
- @mysql_query('set names utf8');
- $this->maxline=$maxline;
-
-
- $this->result=mysql_query($query) or die($this->feedback='System Error ,Please contect admin');
- if($count=mysql_fetch_row($this->result)){
-
- $this->countline = intval($count[0]);
- $this->countpage = ceil($this->countline/$maxline);
- }
-
- if($page<=$this->countpage){
- $this->page=$page;
- }
-
- if($this->page<2){
- $this->prevpage=0;
- $this->nextpage=2;
- $this->startline= 0;
- }elseif($this->page==$this->countpage){
- $this->prevpage=$this->page-1;
- $this->nextpage=0;
- $this->startline= ($this->page-1)*$this->maxline;
- }else{
- $this->prevpage=$this->page-1;
- $this->nextpage=$this->page+1;
- $this->startline= ($this->page-1)*$this->maxline;
- }
- }
-
-
-
-
- public function __destruct(){
- mysql_free_result($this->result);
- mysql_close($this->link);
- exit();
- }
-
-
-
-
- public function showpage(){
-
- $listnum=10;
- echo $this->countline." Items, ".$this->countpage." Pages ";
- if($this->prevpage==0){
- echo "<<Prev ";
- }else{
- echo "<a href=?page=".$this->prevpage."><<Prev</a> ";
- }
-
- if($this->countpage<$listnum){
- $page_start=1;
- $page_end=$this->countpage;
- }elseif($this->page<$listnum/2){
- $page_start=1;
- $page_end=$listnum;
- }elseif($this->page>$this->countpage-($listnum/2)){
- $page_start=$this->countpage-($listnum-1);
- $page_end=$this->countpage;
- }else{
- $page_start=$this->page-($listnum/2-1);
- $page_end=$this->page+($listnum/2);
- }
-
- for($i=$page_start;$i<=$page_end;$i++){
- if($i==$this->page){
- echo "<b>".$i."</b> ";
- }else{
- echo "<a href=?page=".$i.">".$i."</a> ";
- }
- }
-
- if ($this->nextpage==0){
- echo " Next>>";
- }else{
- echo " <a href=?page=".$this->nextpage.">Next>></a> ";
- }
-
- }
-
-
-
-
-
- public function showtable($query){
- $query=$query." LIMIT ".$this->startline.",".$this->maxline;
- $result = mysql_query($query) or die($this->feedback='System Error ,Please contect admin');
-
- $i=0;
- while ($fetch = mysql_fetch_assoc($result)){
- $i++;
- echo "<tr><td>".$i."</td>";
-
- foreach ($fetch as $value){
- echo "<td>".$value."</td>";
- }
- echo "</tr>";
- }
- }
-
-
-
- public function showresult($query){
- $result = mysql_query($query) or die($this->feedback='System Error ,Please contect admin');
- return $result;
- }
- }
- ?>
(责任编辑:admin) |