php dz分页类

?php/*** 分页类 20080505 ***/
require_once(‘mysql.php’);//mysql.php文件在上一篇日志class page{
private $url; private $pagesize; private $sql; private $getpage;
//参数:sql语句,每页记录数,传递链接(例如index.php?或者index.php?sort=1等)
function __construct($sql,$pagesize,$url) { $this-url= $url;
$this-pagesize = $pagesize; $this-sql= $sql; $this-getpage=
$_GET[page]; if(!$this-getpage) { $this-getpage=1; } } //取记录总数
function getcount() { return mysql_num_rows(mysql_query($this-sql));
} //格式化sql语句 function pagesql() { $nowpage= $this-getpage;
$limitNumber= $this-pagesize; if($nowpage1) { $nowpage=1; } return
$this-sql. limit .($nowpage-1)*$limitNumber.,.$limitNumber; }
//显示分页,参数:显示数字链接个数,开始步进的页 function show($page =
5,$offset = 2){ $mpurl = $this-url; $curr_page = $this-getpage;
$perpage = $this-pagesize; $num=$this-getcount();//总记录数 $multipage =
; if ($num $perpage){ $pages = ceil($num / $perpage); $from =
$curr_澳门新葡亰手机版,page – $offset; $to = $curr_page + $page – $offset – 1; if
($page $pages){ $from = 1; $to = $pages; }else{ if ($from 1){ $to =
$curr_page + 1-$from; $from = 1; if (($to – $from) $page ($to – $from)
$pages){ $to = $page; } }elseif ($to $pages){ $from = $curr_page –
$pages + $to; $to = $pages; if (($to – $from) $page ($to – $from)
$pages){ $from = $pages – $page + 1; } } } $multipage .= script
language=/javascript/ function gotoPage(value) { value =
parseInt(value); if(isNaN(value)) value = 0; if(value1) value = 1;
if(value.$pages.) value = .$pages.; window.location.href =
/.$mpurl.page=/+value; } /script; $multipage .= div class=/p_bar/;
$multipage .= a class=/p_total/.$num./a/n; $multipage .= a
class=/p_pages/.$curr_page./.$pages./a/n; if ($curr_page – $offset
1){ $multipage .= a class=/p_redirect/ href=/.$mpurl.page=1/
title=’首页’/a/n; } for ($i = $from; $i = $to; $i++){ if ($i !=
$curr_page){ $multipage .= a class=/p_num/ href=/.$mpurl.page=.$i./
title=’第.$i.页’.$i./a/n; }else{ $multipage .= a
class=/p_curpage/.$i./a/n; } } if ($curr_page + $offset $pages){
$multipage .= a class=/p_redirect/ href=/.$mpurl.page=$pages/
title=’尾页’/a/n; } $multipage .= input class=/p_input/
title=/输入页数,按回车跳转/ name=/pageGo/ id=/pageGo/
onKeydown=/if(event.keyCode == 13) {gotoPage(this.value);return
false;}//n; //$multipage .= a class=/p_total/.$perpage.条/页/a/n;
$multipage .= /div; } return $multipage; } } ?