本文目录一览:
- 1、求简单的php分页代码一定要是简单最好可以详细解释的,如果可以希望高手能把这段代码加上分页
- 2、将分页的PHP代码封装成函数在查询页面怎么调用?
- 3、关于PHP分页
- 4、php thinkphp3.2.3怎么做分页样式
求简单的php分页代码一定要是简单最好可以详细解释的,如果可以希望高手能把这段代码加上分页
body
?
/*
'PID 页面中的其它传参连接
'page 要显示的页码
'Vcount 总记录数
'Pnum 每页记录数
'className 超连接样式
*/
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='?".$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='?".$Pid."page=".$go."'".$go."/a";
}else{
$show = $show."b".$go."/b";
}
$show = $show." ";
}
if($EndPageNum$Pcount) $show = $show."a class='".$className."' href='?".$Pid."page=".($EndPageNum+1)."' title='下十页'font face='webdings'8/font/a";
$show = $show."] 页";
if($page!=1) $show = $show."a class='".$className."' href='?".$Pid."page=1' 首页/a a class='".$className."' href='?".$Pid."page=".($page-1)."'上一页/a";
if($Pcount-$page!=0) $show = $show. "a class='".$className."' href='?".$Pid."page=".($page+1)."' 下一页/a a class='".$className."' href='?".$Pid."page=".$Pcount."'尾页/a";
$show=$show."/tr/td";
return $show;
}
?
?php
//连上数据库
mysql_connect("localhost","root","");
//选择数据库
mysql_select_db("company");
//执行数据库命令
mysql_query("set names 'utf8'");
//关闭数据库就是使用的最近的数据库
echo "afont color=red已查到的记录:/font/a"."font color=red
共".mysql_num_rows
($rs)."条/font"."br"."br";
?
input type="button" value="添加员工" onclick="location.href='empadd.html'" /
form class="bd"
table border="1" align="left" bordercolor="blue" background="27[1].jpg"
td align="center"font color=#0000FF职员编号/font/td
td align="center"font color=#0000FF职员姓名/font/td
td align="center"font color=#0000FF职员职位/font/td
td align="center"font color=#0000FF职员经理/font/td
td align="center"font color=#0000FF入职日期/font/td
td align="center"font color=#0000FF职员工资/font/td
td align="center"font color=#0000FF所在部门/font/td
td align="center" width="100" height="20"font color=#0000FF操作/font/td
/tr
?
//设置参数
$page = $_REQUEST["page"];
if($page=="") $page = 1;
$Pid = "";
$Pnum = 10;
$classname = "lwf";
//以下不用修改
$rs = mysql_query("select count(*) from emp e1 left join emp e2 on e1.mgr = e2.empno left join dept on e1.deptno = dept.deptno");
$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 e1.empno, e1.ename, e1.job, e1.mgr, e1.hiredate, e1.sal, e1.deptno, e2.ename as mname, dname from emp e1 left join emp e2 on e1.mgr = e2.empno left join dept on e1.deptno = dept.deptno LIMIT $start,$limit");
while($ary = mysql_fetch_array($rs)){
?
tr bordercolor="blue"
td width="80" height="20" align="center"?php echo $a["empno"];? /td
td width="80" height="20" align="center"?php echo $a["ename"];? /td
td width="80" height="20" align="center"?php echo $a["job"];? /td
td width="80" height="20" align="center"?php echo $a["mname"];? /td
td width="150" height="20" align="center"?php echo $a["hiredate"];? /td
td width="80" height="20" align="center"?php echo $a["sal"];? /td
td width="80" height="20" align="center"?php echo $a["dname"];? /td
td width="90" height="20" align="center"
a href="empedit.php?aa=?php echo $a['empno']?"修改/a |
a href="empdel.php?aa=?php echo $a['empno']?"删除/a/td
/tr
?
}
@mysql_free_result($rs);
echo ThePage($Pid,$page,$Vcount,$Pnum,$classname);
?
/table
/form
/body
将分页的PHP代码封装成函数在查询页面怎么调用?
难道不是
echo pageshwo(Sql语句,显示字段数)?
这个只是显示分页链接的。应该还有一个别的类用于显示数据的吧
关于PHP分页
一个分页函数,赋好值就可以使用了
/*
'PID 页面中的其它传参连接
'page 要显示的页码
'Vcount 总记录数
'Pnum 每页记录数
'className 超连接样式
*/
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='?".$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='?".$Pid."page=".$go."'".$go."/a";
}else{
$show = $show."b".$go."/b";
}
$show = $show." ";
}
if($EndPageNum$Pcount) $show = $show."a class='".$className."' href='?".$Pid."page=".($EndPageNum+1)."' title='下十页'font face='webdings'8/font/a";
$show = $show."] 页";
if($page!=1) $show = $show."a class='".$className."' href='?".$Pid."page=1' 首页/a a class='".$className."' href='?".$Pid."page=".($page-1)."'上一页/a";
if($Pcount-$page!=0) $show = $show. "a class='".$className."' href='?".$Pid."page=".($page+1)."' 下一页/a a class='".$className."' href='?".$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 thinkphp3.2.3怎么做分页样式
$id = I("id");
$Cate = M('Article'); // 实例化Cate对象
$count = $Cate-where("cate=$id")-count(); // 查询满足要求的总记录数
$Page = new \Think\Page($count, 32); // 实例化分页类 传入总记录数和每页显示的记录数(25)
$Page-setConfig('header', '条数据');
$Page-setConfig('prev', '上一页');
$Page-setConfig('next', '下一页');
$Page-setConfig('first', '首页');
$Page-setConfig('end', '末页');
$show = $Page-show(); // 分页显示输出
$list = $Cate-where("cate=$id")-order('id DESC')-limit($Page-firstRow . ',' . $Page-listRows)-select();
$this-assign('list', $list); // 赋值数据集
$this-assign('page', $show); // 赋值分页输出
//大家都在看
$click = M('article')-limit(8)-order("click DESC")-select();
$this-assign('click', $click);
//最新资讯
$news = M('article')-limit(8)-order("click DESC")-select();
$this-assign('news', $news);
$this-display();