php数据表做分页就出错 php数据库分页

关于PHP分页一个分页函数,赋好值就可以使用了
/*
'PID页面中的其它传参连接
'page要显示的页码
'Vcount总记录数
'Pnum每页记录数
'className超连接样式
【php数据表做分页就出错 php数据库分页】*/
function ThePage($Pid,$page=1,$Vcount,$Pnum,$className){
$Pcount = ceil($Vcount/$Pnum);
if($page$Pcount) $page=$Pcount;
$StartPageNum=1;
while($StartPageNum 10=$page){
$StartPageNum=$StartPageNum 10;
}
$EndPageNum=$StartPageNum 9 ;
if($EndPageNum$Pcount) $EndPageNum=$Pcount;
$show = $show."trtd colspan='10' bgcolor='' align='right' style='padding-right:25px;padding-top:5px;' class='".$className."'";
$show = $show."共b".$Pcount."/b页 共有b".$Vcount."/b记录 第b".$page."/b页 跳到第 [ ";
if($StartPageNum1) $show = $show."a class='".$className."' href='https://www.04ip.com/post/?".$Pid."page=".($StartPageNum-1)."' title='前十页'font face='webdings'7/font/a";
for($go=$StartPageNum;$go=$EndPageNum;$go){
if($go!=$page){
$show = $show."a class='".$className."' href='https://www.04ip.com/post/?".$Pid."page=".$go."'".$go."/a";
}else{
$show = $show."b".$go."/b";
}
$show = $show." ";
}
if($EndPageNum$Pcount) $show = $show."a class='".$className."' href='https://www.04ip.com/post/?".$Pid."page=".($EndPageNum 1)."' title='下十页'font face='webdings'8/font/a";
$show = $show."] 页";
if($page!=1) $show = $show."a class='".$className."' href='https://www.04ip.com/post/?".$Pid."page=1' 首页/a a class='".$className."' href='https://www.04ip.com/post/?".$Pid."page=".($page-1)."'上一页/a";
if($Pcount-$page!=0) $show = $show. "a class='".$className."' href='https://www.04ip.com/post/?".$Pid."page=".($page 1)."' 下一页/a a class='".$className."' href='https://www.04ip.com/post/?".$Pid."page=".$Pcount."'尾页/a";
$show=$show."/tr/td";
return $show;
}
========================附带一个使用例子=============================
?
//设置参数
$page = $_REQUEST["page"];
if($page=="") $page = 1;
$T = $_GET["T"];
if($T=="") $T = 1;
$Pid = "T=".$T."";
$wheresql = "where T = ".$T;
$recordListTable = "zc_news";
$Pnum = 10;
$classname = "lwf";
//以下不用修改
$rs = mysql_query("select count(*) from `".$recordListTable."` $wheresql ");
$Vcount = @mysql_result($rs,0);
@mysql_free_result($rs);
$start = ($page - 1) * $Pnum;
$lastNum = $Vcount - ($page - 1) * $Pnum;
$limit = $lastNum$Pnum ? $Pnum : $lastNum;
$rs = mysql_query("select * from `".$recordListTable."` $wheresql order by orderid desc,ID desc LIMIT $start,$limit");
while($ary = mysql_fetch_array($rs)){
?
tr
td标题/td
/tr
?
}
@mysql_free_result($rs);
echo ThePage($Pid,$page,$Vcount,$Pnum,$classname);
?
php分页问题 。。求助 。。。好好读读代码这次我把代码写php数据表做分页就出错了一遍php数据表做分页就出错 , 你在你本地调试一下!回头在网上下载一个中文手册,这是必备的东西 , 有用的很!
?php
require_once 'inc.php'; 数据库链接文件
pagesize = 30;
$url = $_SERVER["REQUEST_URI"];
$url = parse_url($url);
$url = $url[path];
$result = mysql_query("SELECT * FROM `Maillist`");
$num = mysql_num_rows($result);
if ($_GET[page] == null || $_GET[page] == 0) {
$pageval = 1;
} else {
$pageval = $_GET[page];
}
$lastpage = round($num / $pagesize0.5);
if ($num$pagesize) {
if ($pageval = 1)
$pageval = 1;
echo "a href=https://www.04ip.com/post/$url?page=1 首页 /a" . "a href=https://www.04ip.com/post/$url?page=" . ($pageval -1) . "上一页/a a href=https://www.04ip.com/post/$url?page=" . ($pageval1) . "下一页/a" . "?" . "a href=https://www.04ip.com/post/$url?page=" . $lastpage . " 尾 页 /a" . "共 $num 条记录" . " 30条/页" . "第 $pageval 页";
} else
echo "a href=https://www.04ip.com/post/$url?page=1 首页 /a" . "a href=https://www.04ip.com/post/$url?page=" . ($pageval -1) . "上一页/a a href=https://www.04ip.com/post/$url?page=" . ($pageval1) . "下一页/a" . "?" . "a href = https://www.04ip.com/post/$url?page =" . $lastpage . "尾 页 /a" . "共 $num 条记录" . " 30条/页" . " 第 $pageval 页";
$sql = "SELECT * FROM Maillist" . ($pageval -1) * $pagesize . ",$pagesize";
$query = mysql_query($sql);
while ($rs = mysql_fetch_array($query)) {
?
form action="" method="GET"
td width="761" valign="top"table width="92%" border="0" cellpadding="3" cellspacing="1" bgcolor="#D7D7FF"
tr
td width="18%" align="center" class="tinymenutextblock"编号/td
td width="16%" align="center" class="tinymenutextblock"姓名/td
td width="66%" align="center"class="tinymenutextblock"邮件地址 /td
/tr
tr
td bgcolor="#FFFFFF"?php echo $rs['ID']?/td
td bgcolor="#FFFFFF"?php echo $rs['UserName']?/td
td bgcolor="#FFFFFF"?php echo $rs['UserMail']?/td
/tr
/form
?php
}
?
php 表格分页 边界控制问题总页数=ceil(总条数/每页显示条数)
其中总条数是可以通过SELECT count(*) FROM 表查到的,每页显示条数是自己定的
ceil()函数是向上取整,这样就得到了总页数
你可以在下一页这里判断
if(当前页=总页数){
echo “下一页”
}else{
echo "a下一页/a"
}
就是如果当前页超过了总页数,那么就去掉下一页的a连接,这样下一页就不会在跳了
一般的分页类都是这么判断
希望对你有帮助
php数据表做分页就出错的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于php数据库分页、php数据表做分页就出错的信息别忘了在本站进行查找喔 。

    推荐阅读