<?
if(!function_exists(pageft)){
function pageft($totle,$displaypg=20,$url=''){
global $page,$firstcount,$pagenav,$_SERVER;
$GLOBALS["displaypg"]=$displaypg;if(!$page) $page=1;
if(!$url){ $url=$_SERVER["REQUEST_URI"];}
$parse_url=parse_url($url);
$url_query=$parse_url["query"];
if($url_query){
$url_query=ereg_replace("(^|&)page=$page","",$url_query);
$url=str_replace($parse_url["query"],$url_query,$url);
if($url_query) $url.="&page"; else $url.="page";
}else {
$url.="?page";
}
$lastpg=ceil($totle/$displaypg);
$page=min($lastpg,$page);
$prepg=$page-1;
$nextpg=($page==$lastpg ? 0 : $page+1);
$firstcount=($page-1)*$displaypg;
$pagenav="";
if($lastpg<=1) return false;
if($page!=1) $pagenav.=" <a href='$url=1'> <img src=\"".WWW.BACK."images/first.jpg\" width=\"64\" height=\"16\" border=\"0\"></a> "; else $pagenav.=" <img src=\"".WWW.BACK."images/first.gif\" width=\"64\" height=\"16\" border=\"0\"> ";
if($prepg) $pagenav.="<a href='$url=$prepg'><img src=\"".WWW.BACK."images/previous.jpg\" width=\"81\" height=\"16\" border=\"0\"></a> "; else $pagenav.="<img src=\"".WWW.BACK."images/previous.gif\" width=\"81\" height=\"16\"> ";
if($nextpg) $pagenav.="<a href='$url=$nextpg'><img src=\"".WWW.BACK."images/next.jpg\" width=\"81\" height=\"16\" border=\"0\"></a>"; else $pagenav.="<img src=\"".WWW.BACK."images/next.gif\" width=\"81\" height=\"16\">";
if($page!=$lastpg) $pagenav.=" <a href='$url=$lastpg'><img src=\"".WWW.BACK."images/last.jpg\" width=\"64\" height=\"16\" border=\"0\"></a>"; else $pagenav.=" <img src=\"".WWW.BACK."images/last.gif\" width=\"64\" height=\"16\" border=\"0\">";
$pagenav.=" Goto<select name='topage' style='font-size:9px' size='1' onchange='window.location=\"$url=\"+this.value'>\n";
for($i=1;$i<=$lastpg;$i++){
if($i==$page) $pagenav.="<option value='$i' selected>$i</option>\n";
else $pagenav.="<option value='$i'>$i</option>\n";
}
$pagenav.="</select> 共:$lastpg 页$totle 条记录";
}
}
?>调用
$result = mysql_query($query,$link) or die("查询异常中断 : " . mysql_error($link));
$total=countTB("product delfag=0 $where");//countTB统计总记录条数
pageft($total,25,$pageSelf);
$result=mysql_query("$query limit $firstcount,$displaypg");<? echo $pagenav;?>显示页码
if(!function_exists(pageft)){
function pageft($totle,$displaypg=20,$url=''){
global $page,$firstcount,$pagenav,$_SERVER;
$GLOBALS["displaypg"]=$displaypg;if(!$page) $page=1;
if(!$url){ $url=$_SERVER["REQUEST_URI"];}
$parse_url=parse_url($url);
$url_query=$parse_url["query"];
if($url_query){
$url_query=ereg_replace("(^|&)page=$page","",$url_query);
$url=str_replace($parse_url["query"],$url_query,$url);
if($url_query) $url.="&page"; else $url.="page";
}else {
$url.="?page";
}
$lastpg=ceil($totle/$displaypg);
$page=min($lastpg,$page);
$prepg=$page-1;
$nextpg=($page==$lastpg ? 0 : $page+1);
$firstcount=($page-1)*$displaypg;
$pagenav="";
if($lastpg<=1) return false;
if($page!=1) $pagenav.=" <a href='$url=1'> <img src=\"".WWW.BACK."images/first.jpg\" width=\"64\" height=\"16\" border=\"0\"></a> "; else $pagenav.=" <img src=\"".WWW.BACK."images/first.gif\" width=\"64\" height=\"16\" border=\"0\"> ";
if($prepg) $pagenav.="<a href='$url=$prepg'><img src=\"".WWW.BACK."images/previous.jpg\" width=\"81\" height=\"16\" border=\"0\"></a> "; else $pagenav.="<img src=\"".WWW.BACK."images/previous.gif\" width=\"81\" height=\"16\"> ";
if($nextpg) $pagenav.="<a href='$url=$nextpg'><img src=\"".WWW.BACK."images/next.jpg\" width=\"81\" height=\"16\" border=\"0\"></a>"; else $pagenav.="<img src=\"".WWW.BACK."images/next.gif\" width=\"81\" height=\"16\">";
if($page!=$lastpg) $pagenav.=" <a href='$url=$lastpg'><img src=\"".WWW.BACK."images/last.jpg\" width=\"64\" height=\"16\" border=\"0\"></a>"; else $pagenav.=" <img src=\"".WWW.BACK."images/last.gif\" width=\"64\" height=\"16\" border=\"0\">";
$pagenav.=" Goto<select name='topage' style='font-size:9px' size='1' onchange='window.location=\"$url=\"+this.value'>\n";
for($i=1;$i<=$lastpg;$i++){
if($i==$page) $pagenav.="<option value='$i' selected>$i</option>\n";
else $pagenav.="<option value='$i'>$i</option>\n";
}
$pagenav.="</select> 共:$lastpg 页$totle 条记录";
}
}
?>调用
$result = mysql_query($query,$link) or die("查询异常中断 : " . mysql_error($link));
$total=countTB("product delfag=0 $where");//countTB统计总记录条数
pageft($total,25,$pageSelf);
$result=mysql_query("$query limit $firstcount,$displaypg");<? echo $pagenav;?>显示页码
解决方案 »
- 一个关于sprintf的问题
- 求一复杂sql语句写法,要求效率较高
- 这段PHP代码有什么作用?
- PHP與session的問題急急急....
- 注意:postgresql-8.0-beta1已经发布,支持win32平台
- 怎样才能将上传的图片按要求的大小显示
- 新手求助--URL传递的值怎么获取啊?
- 兄弟们,救救我吧,一百年一次,谁能将其linux版的php下de extension文件传给我,我好郁闷,我的系统中默认装的php下竟然没有mysql.so,我
- 大家能不能给个网站的分析,设计(包括数据库)的模板
- phpmailer
- access的备注字段到底能容纳多少字符串?
- 关于func_get_args();求解!
class Pages
{
var $offset;
var $nextp;
var $frontp;
var $perpage;
var $total;//construction
function Pages($offset,$perpage,$total)
{
$this->setOffset($offset);
$this->setPerpage($perpage);
$this->setTotal($total);
$this->setNextp();
$this->setFrontp();
//echo $this->offset." ".$this->perpage." ".$this->frontp." ".$this->nextp;
}// set perpage
function setPerpage($perpage)
{
$this->perpage=$perpage;
}
function getPerpage()
{
return isset($this->perpage)? $this->perpage : 0;
}
//set total
function setTotal($total)
{
$this->total=$total;
}
function getTotal()
{
return isset($this->total)? $this->total : 0;
}
//set offset
function setOffset($offset)
{
$this->offset=$offset;
}
function getOffset()
{
return isset($this->offset)? $this->offset : 0;
}
//set nextp
function setNextp()
{
$this->nextp=$this->offset+$this->perpage;
if($this->nextp>=($this->total))$this->nextp=$this->offset;
}
function getNextp()
{
return isset($this->nextp)? $this->nextp : $this->$offset;
}
//set front
function setFrontp()
{
$this->frontp=$this->offset-$this->perpage;
if($this->frontp<0)$this->frontp=0;
}
function getFrontp()
{
return isset($this->frontp)? $this->frontp : $this->$offset;
}
function getCurPage()
{
return ceil($this->offset/$this->perpage)+1;
}
function getPages()
{
if($this->perpage==0)return 0;
else return ceil($this->total/$this->perpage);
}
}
?>自已查出记录总数$total 定义初始变量$offset每页显示数目$perpage
将上面的文件include后include "pg.php";
$offset=$_GET["offset"];
if(!isset($offset))$offset=0;$perpage=10;//每页显示数$str_sql="select count(id) as total from table";//写自己想要的sql语句
$str_sql_show="select * from table limit ".$offset.",".$perpage;//显示数据的sql
/*
数据显示查询输出略
*/
$arr=mysql_fetch_array(mysql_query($str_sql,$conn));
$total=$arr["total"];$pg=new Pages($offset,$perpage,$total);
$pg->getNextp();//取得下一页的初始偏移量
$pg->getFrontp();//取得上一页的初始偏移量
$pg->getCurPage();//取得当前页码
$pg->getPages();//取得总共页数
/*
输出上一页下一页等的A元素代码略
*/样式自己定吧
class Pages
{
var $offset;
var $nextp;
var $frontp;
var $perpage;
var $total;//construction
function Pages($offset,$perpage,$total)
{
$this->setOffset($offset);
$this->setPerpage($perpage);
$this->setTotal($total);
$this->setNextp();
$this->setFrontp();
//echo $this->offset." ".$this->perpage." ".$this->frontp." ".$this->nextp;
}// set perpage
function setPerpage($perpage)
{
$this->perpage=$perpage;
}
function getPerpage()
{
return isset($this->perpage)? $this->perpage : 0;
}
//set total
function setTotal($total)
{
$this->total=$total;
}
function getTotal()
{
return isset($this->total)? $this->total : 0;
}
//set offset
function setOffset($offset)
{
$this->offset=$offset;
}
function getOffset()
{
return isset($this->offset)? $this->offset : 0;
}
//set nextp
function setNextp()
{
$this->nextp=$this->offset+$this->perpage;
if($this->nextp>=($this->total))$this->nextp=$this->offset;
}
function getNextp()
{
return isset($this->nextp)? $this->nextp : $this->$offset;
}
//set front
function setFrontp()
{
$this->frontp=$this->offset-$this->perpage;
if($this->frontp<0)$this->frontp=0;
}
function getFrontp()
{
return isset($this->frontp)? $this->frontp : $this->$offset;
}
function getCurPage()
{
return ceil($this->offset/$this->perpage)+1;
}
function getPages()
{
if($this->perpage==0)return 0;
else return ceil($this->total/$this->perpage);
}
}
?>自已查出记录总数$total 定义初始变量$offset每页显示数目$perpage
将上面的文件include后include "pg.php";
$offset=$_GET["offset"];
if(!isset($offset))$offset=0;$perpage=10;//每页显示数$str_sql="select count(id) as total from table";//写自己想要的sql语句
$str_sql_show="select * from table limit ".$offset.",".$perpage;//显示数据的sql
/*
数据显示查询输出略
*/
$arr=mysql_fetch_array(mysql_query($str_sql,$conn));
$total=$arr["total"];$pg=new Pages($offset,$perpage,$total);
$pg->getNextp();//取得下一页的初始偏移量
$pg->getFrontp();//取得上一页的初始偏移量
$pg->getCurPage();//取得当前页码
$pg->getPages();//取得总共页数
/*
输出上一页下一页等的A元素代码略
*/样式自己定吧