本文章提供一款php分页代码,这是一款比较简单也常的limit进来分页了,同时他还带有条件查询分页功能,代码如下:
-
$conn=mysql_connect($mysql_host,$mysql_user,$mysql_password) or die('连接服务器出错');
-
mysql_select_db($mysql_db) or die("选择数据库教程出错");
-
mysql_query("set names 'gbk'");
-
function table($t)
-
{
-
global $mysql_table_prefix;
-
return $mysql_table_prefix.$t;
-
}
-
-
$sql="select * from ".table('keywords')." where 1=1 ";
-
$sql2="select count(*) from ".table('keywords')." where 1=1 ";
-
$py=trim($_request['py']);
-
if($act=="search" and !emptyempty($_post['s1']))
-
{
-
$s1=trim($_post['s1']);
-
$sql .=" and (k1='$s1' or k2='$s1') ";
-
$sql2 .=" and (k1='$s1' or k2='$s1') ";
-
}
-
elseif(!emptyempty($py))
-
{
-
$sql .=" and pinyin='$py' ";
-
$sql2.=" and pinyin='$py' ";
-
}
-
-
$sql .=" order by pinyin ";
-
$rscount=mysql_query($sql2);
-
$rscount=@mysql_fetch_array($rscount);
-
$rscount=$rscount[0];
-
$page=trim($_get['page']);
-
$pagesize=30;
-
$pagecount=ceil($rscount/$pagesize);
-
$pageurl="";
-
if($page<=1)
-
{
-
$page=1;
-
$pageurl.=" 首页 上一页";
-
}else
-
{
-
$pageurl .=" <a href='?page=1&py=".$py."'>首页</a> <a href='?py=".$py."&page=".($page-1)."'>上一页</a>";
-
}
-
if($page>=$pagecount)
-
{
-
$page=$pagecount;
-
$pageurl .=" 下一页 尾页";
-
}else
-
{
-
$pageurl .=" <a href='?py=".$py."&page=".($page+1)."'>下一页</a> <a href='?py=".$py."&page=".$pagecount."'>尾页</a>";
-
}
-
$start_rs=($page-1)*$pagesize;
-
$end_rs=$page*$pagesize;
-
$sql .=" limit {$start_rs},{$end_rs} ";
-
$res=mysql_query($sql);