澳门新葡萄京官网注册php经典分页类

?phpclass conn{function __construct(){ require(config.php); $conn =
@mysql_connect($host,$root,$pass); @mysql_select_db($db); if(!$conn){
echo 无法连接.mysql_errno() . : . mysql_error() ; exit; }}function
query($sql){ $result = @mysql_query($sql); if (!$result) { echo
mysql_errno().:.mysql_error(); exit; } return $result;}function
next($result){ return @mysql_fetch_array($result);}function
count_row($result){ $row = @mysql_num_rows($result); return
$row;}function close($result){ @mysql_free_result($result);
@mysql_close();}}class fenye extends conn{public $sql;public
$page;public $countpage;public $pagesize;public $result;function
__construct($sql,$page,$pagesize){ $this-sql = $sql; $this-page =
$page; $this-countpage = $countpage; $this-pagesize = $pagesize;
parent::__construct(); $result = parent::query($sql); $num =
parent::count_row($result); $this-countpage = ceil($num/$pagesize); $a
= ($page-1)*$pagesize; $limit = limit $a,$pagesize; $this-sql =
$sql.$limit; $this-result = parent::query($this-sql);}function
getlimit(){ return $this-sql;} function next(){ return
parent::next($this-result); }function foor(){ $a = $this-page -1; $b =
$this-page +1; if ($this-page == 1) { echo 首页. ; }else echo a
href=’?page=1’首页/a. ; if($this-page 1) echo a href=’?page=$a’上页/a. ;
else echo 上页 ; for ($i =1;$i = $this-countpage;$i++){ echo a
href=’?page=$i’$i/a. ; } if($this-page $this-countpage) echo a
href=’?page=$b’下页/a. ; else echo 下页 ; if ($this-page ==
$this-countpage) { echo 末页. ; }else echo a
href=’?page=$this-countpage’末页/a;
#######################澳门新葡萄京官网注册
}}####################if (isset($_GET[‘page’]))
{$page = $_GET[‘page’];}else $page = 1;$sql = select * from
guestbook ;$pagesize =3;$p = new fenye($sql,$page,$pagesize); $sql =
$p-getlimit();$result = $p-query($sql);while($row = $p-next()){echo
$row[‘id’].br;}$p-foor();$p-close($result);?

php经典分页类

?phpclass db{public $conn,$db,$table,$user,$host,$unm,$pwd;public
$res;public $char;public $linkType;function
__construct($linkType=false,$char=gb2312){
$this-linkType=$linkType;//设定连接类型
$this-char=$char;//设定连接校对字符 $this-db=DB; $this-user=USER;
$this-host=HOST; $this-unm=UNM; $this-pwd=PWD; if($this-linkType) {
$this-conn=mysql_pconnect($this-host,$this-unm,$this-pwd) or
die(Database connection failure); } else {
$this-conn=mysql_connect($this-host,$this-unm,$this-pwd) or
die(Database connection failure); } mysql_select_db($this-db);
mysql_query(set names .$this-char); }function query($sql,$type=true){
//$type:默认的操作。 指代select操作 $this-res=mysql_query($sql) or
die(SQL Statement error !Please check it again);
$row=$type?mysql_num_rows($this-res):mysql_affected_rows();
$result[res]=$this-res; $result[row]=$row; return
$result;}//fetch()方法:获取所有的记录,并写入数组function fetch($sql){
$res=self::query($sql); while ($rs=mysql_fetch_array($res[res])) {
$result[]=$rs; } return $result;}//获取下一条记录function
fetchNext($filed,$currenID,$table){ $sql=select * from $table where
$filed$currenID limit 0,1 ; return
self::fetch($sql);}//获取前一条记录function
fetchPre($filed,$currenID,$table){ $sql=select * from $table where
$filed$currenID limit 0,1 ; return self::fetch($sql);} }class page
extends db {public $currentPage,$totalRecord,$totalPage,$pageSize;public
$start;public $flag;public $sql;function
__construct($sql,$pagesize=5,$flag=page){ $this-sql=$sql;
$this-pageSize=$pagesize; $this-flag=$flag;//设定翻页链接标识符
$row=parent::query($sql); $this-totalRecord=$row[row];
$this-totalPage=ceil($this-totalRecord/$this-pageSize);
$page=$_REQUEST[$this-flag]; if($page0||$page==) {
$this-currentPage=1; } else {
$page$this-totalPage?$this-currentPage=$this-totalPage:$this-currentPage=$page;
} $this-start=($this-currentPage-1)*$this-pageSize;
}//显示分页列表function show($page=10){ $str.=’div class=pages_btnsdiv
class=pages’; $str.=em .$this-totalRecord. /em;
$pre=$this-currentPage-1; if($pre!=0) { $str.=’a
href=?’.$this-flag.’=’.$pre.’ class=next/a’; }
if($this-currentPage=$page) { if($this-totalPage-$this-currentPage10) {
$start=$this-currentPage-($this-currentPage%10); $end=$this-totalPage; }
else { $start=$this-currentPage-2; $end=$start+$page-1; } } else {
$start=1; $end=10; } for ($i=$start;$i=$end;$i++) {
if($i==$this-currentPage) { $str.=strong.$i./strong; } else { $str.=a
href=?.$this-flag.=$i$i/a; } } $next=$this-currentPage+1; $str.=’a
href=?’.$this-flag.’=’.$next.’ class=next/a’; $str.=a
href=?.$this-flag.=.$this-totalPage. class=last….$this-totalPage./a;
$str.=kbdinput type=’text’ name=’custompage’ size=’3′
onkeydown=/if(event.keyCode==13)
{window.location='{$_SERVER[‘PHP_SELF’]}?{$this-flag}=’+this.value;
return false;}/ //kbd; $str.=/div/div; return
$str;}}??phpdefine(HOST,localhost);define(UNM,root);define(PWD,root);define(DB,test);require_once(‘db.class.php’);$db=new
db();$sql=select * from yy; $page=new page($sql,10); $sql.= limit
$page-start,$page-pageSize;$rs = $db-fetch($sql);?table width=100%
border=0 cellpadding=0 cellspacing=1 bgcolor=#FF0000 tr td height=25
bgcolor=#FFFFFFID/td td bgcolor=#FFFFFFUNM/td /tr ?php
for($i=0;$icount($rs);$i++) { ? tr td height=25
bgcolor=#FFFFFF?=$rs[$i][0]?/td td
bgcolor=#FFFFFF?=$rs[$i][1]?/td /tr ?php } ? tr td height=25
colspan=2 bgcolor=#FFFFFF?=$page-show()?/td /tr/table

发表评论

电子邮件地址不会被公开。 必填项已用*标注