搜尋
首頁php教程PHP源码自己写的非常简单好用的PHP的MYSQL分页类


dbadd=$dbadd;
		$this->dbuser=$dbuser;
		$this->dbpwd=$dbpwd;
		$this->dbname=$dbname;
		$this->tablename=$tablename;
		$this->num=$num;
		$this->total=$this->gettotal();	//得到总条数
		$this->totalpage=ceil($this->total/$this->num); //获取总页数
		$this->page=$this->getpage(); //得到当前页数
		$this->limit=$this->setlimit(); //得到查询的数据
		$this->arrs=$this->getarrs(); //得到查询的结果		
		$this->col=$this->getcol(); //获取总列数
		$this->nostart=($this->page-1)*$num+1;
		$this->noend=$this->page==$this->totalpage ? $this->total : $this->page*$num;
		$this->head=$this->page==1 ? "首页" : "首页";
		$this->end=$this->page==$this->totalpage ? "尾页" : "totalpage}" _href=".html?page={$this->totalpage}">尾页";
		$this->last=$this->page==1 ? "上一页" : "page-1)."" _href=".html?page=".($this->page-1)."">上一页";
		$this->nexts=$this->page==$this->totalpage ? "下一页" : "page+1)."" _href=".html?page=".($this->page+1)."">下一页";
	}

	private function getcol(){
		$linkss=mysql_connect($this->dbadd, $this->dbuser, $this->dbpwd);
		mysql_select_db($this->dbname, $linkss);
		$result=mysql_query("select * from {$this->tablename}", $linkss);
		$col=mysql_num_fields($result);
		mysql_close($linkss);
		return $col;
	}

	private function getarrs(){ //根据条件再次查询并返回结果
		$sql="select * from {$this->tablename} limit {$this->limit}, {$this->num}";
		$links=mysql_connect($this->dbadd, $this->dbuser, $this->dbpwd);
		mysql_select_db($this->dbname, $links);	
		$result=mysql_query($sql, $links);	
		while($arr=mysql_fetch_assoc($result)){
			$arrs[]=$arr;
		}
		return $arrs;
		mysql_close($links);
	}

	private function setlimit(){
		return ($this->page-1)*$this->num;
	}

	private function getpage(){
		$page=isset($_GET["page"]) ? $_GET["page"] : 1;
		$page=$page>$this->totalpage ? $this->totalpage : $page;
		$page=$pagedbadd, $this->dbuser, $this->dbpwd);
		mysql_select_db($this->dbname, $link);
		$result=mysql_query("select * from {$this->tablename}", $link);
		$total=mysql_num_rows($result);
		mysql_close($link);
		return $total;
	}

	function __get($args){
		switch($args){
			case "arrs":	//根据条件查询出的结果,是二维数组
				return $this->arrs;
				break;
			case "totalpage":	//总页数
				return $this->totalpage;
				break;
			case "col":	//总列数
				return $this->col;
				break;
			case "page":	//当前页
				return $this->page;
				break;
			case "nostart": //当前页显示的记录的起始条数
				return $this->nostart;
				break;
			case "noend": //当前页显示的记录的结束条数
				return $this->noend;
				break;
			case "head":	//首页按钮
				return $this->head;
				break;
			case "end":	//尾页按钮
				return $this->end;
				break;
			case "last":  //上一页按钮
				return $this->last;
				break;
			case "nexts": //下一页按钮
				return $this->nexts;
				break;
		}
	}
}
?>

                   

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具