设为首页 收藏本站
查看: 690|回复: 0

[经验分享] PHP分页技术通用模版

[复制链接]

尚未签到

发表于 2017-3-25 11:18:34 | 显示全部楼层 |阅读模式
直接进入主题吧!可能不是最好的,但相信自己是自己做的会是最棒的,^_^

首先建一个domain:fenyePage.class.php


<?php
class fenyePage{
public $everyPageRows; //每页显示的行数
public $sumPage; <wbr><wbr><wbr><wbr>//总页数</wbr></wbr></wbr></wbr>
public $nowPage; <wbr><wbr><wbr><wbr>//当前所在页数</wbr></wbr></wbr></wbr>
public $fenyeArray; <wbr><wbr>//分页显示的数据</wbr></wbr>
public $navigate; <wbr><wbr><wbr> //分页导航条</wbr></wbr></wbr>
public $pageWhole; <wbr><wbr><wbr>//翻页页数</wbr></wbr></wbr>
function showNavigate(){
echo "<ulclass='fenye_ul'>";
echo"<li>共{$this->sumPage}页</li>";
echo "<ahref='userList.php?nowPage=1'><li>首页</li></a>";
if($this->nowPage>1){echo"<ahref='userList.php?nowPage=".($this->nowPage-1)."'><liclass='btn'>上页</li></a>";}
//翻页
$startPage =floor(($this->nowPage-1)/$this->pageWhole)* $this->pageWhole + 1;
$index = $startPage;
//如果当前页是在1到10之间,就没有必要显示向前翻页的链接
if($this->nowPage >$this->pageWhole){echo "<ahref='userList.php?nowPage=".($startPage-1)."'><li><b>&lt;&lt;</b></li></a>";}
for(;$startPage<$index +$this->pageWhole;$startPage++){
if($startPage == $this->nowPage){
echo "<ahref='userList.php?nowPage=$startPage'><listyle='background:#6699cc;'>$startPage</li></a>";
}else{
echo "<ahref='userList.php?nowPage=$startPage'><li>$startPage</li></a>";
}
}
//如果startPage的值小于总的页数,就显示向后翻译
if($startPage<$this->sumPage){echo"<ahref='userList.php?nowPage=$startPage'><li><b>&gt;&gt;</b></li></a>";}
if($this->nowPage<$this->sumPage){echo"<ahref='userList.php?nowPage=".($this->nowPage+1)."'><li>下页</li></a>";}
echo "<ahref='userList.php?nowPage={$this->sumPage}'><li>末页</li></a>";
echo "</ul>";
}
}
?>





接着就是分页导航条的一些css样式:global.css
@charset "utf-8";


body{
font-family:Arial, Helvetica, sans-serif ;
font-size:12px;
}


a:link{
text-decoration:none;
color:#333333;
}


a:hover{
text-decoration: none;
color: #006699;
}


a:visited{
text-decoration: none;
color: #008040;
}




.fenye_ul{
list-style-type:none;
padding:0;
float:right;
}
.fenye_ul li{
float:left;
border:1px solid #6699cc;
text-align:center;
margin-left:3px;
padding:2px 5px;
font-size:10px;
}
.fenye_ul .btn{
float:left;
border:1px solid #6699cc;
text-align:center;
margin-left:2px;
font-size:10px;
}



再接着,就是在db.class.php这个工具类中,新建一个分页使用的方法:
//分页查询的方法
function fenyeSelect($sql_arrs,$sql_sumPage,$fenyePage){
//获取分页显示的数据
$res = mysql_query($sql_arrs,$this->conn) ordie(mysql_errno());
$array = array();
while($row = mysql_fetch_row($res)){
$array[] = $row;
}
//释放资源
mysql_free_result($res);
//获取分页所需要的显示数据
$fenyePage->fenyeArray = $array;
//获取总的数据行数
$res2 = mysql_query($sql_sumPage,$this->conn)or die(mysql_errno());
if($rows = mysql_fetch_row($res2)){
//获取总的页数
$fenyePage->sumPage =ceil($rows[0]/$fenyePage->everyPageRows);
}
//释放资源
mysql_free_result($res2);
}



继续,就是在service文件夹中新建对应的一个文件:userService.php
<?php
<wbr></wbr>
require_once '../dao/db.class.php';
class userService{
//获取分页显示数据方法
function getFenYePage($fenyePage){
$dbClass = new dbClass();
$sql_arrs = "selectuser_name,user_gender,user_professional,user_email,user_addr,user_phonefrom user_info order by id limit ".
($fenyePage->nowPage-1)*$fenyePage->everyPageRows.",".$fenyePage->everyPageRows;
$sql_sumPage = "select count(id) from user_info";


$dbClass->fenyeSelect($sql_arrs,$sql_sumPage,$fenyePage);
$dbClass->connClose();
}
}
?>





最后,就是页面层的文件:userList.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"content="text/html; charset=utf-8" />
<title>通讯录管理系统</title>
<link rel="stylesheet" type="text/css"href="css/global.css">
</head>
<body>
<p>友友管理 &gt;友友信息</p>
<hr />
<table width="725" border="1" cellspacing="0"cellpadding="0" style="border-collapse:collapse"bordercolor="#6699CC">
<wbr> &lt;trbgcolor="#6699cc"&gt;</wbr>
<wbr><wbr> &lt;thscope="col"&gt;姓名&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;thscope="col"&gt;性别&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;thscope="col"&gt;专业&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;thscope="col"&gt;Email&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;thscope="col"&gt;籍贯&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;thscope="col"&gt;电话&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;thscope="col"&gt;操&amp;nbsp;作&lt;/th&gt;</wbr></wbr>
<wbr> &lt;/tr&gt;</wbr>
<wbr>&lt;?php<wbr></wbr></wbr>
<wbr> require_once'../domain/fenyePage.class.php';</wbr>
<wbr> require_once'../service/userService.php';</wbr>
<wbr></wbr>
<wbr> $fenyePage = new fenyePage();</wbr>
<wbr></wbr>
<wbr> //如果当前页未获取到,则默认为首页</wbr>
<wbr> $fenyePage-&gt;nowPage =1;</wbr>
<wbr> if(!empty($_GET['nowPage'])){</wbr>
<wbr> $fenyePage-&gt;nowPage =$_GET['nowPage'];</wbr>
<wbr> }</wbr>
<wbr> //设置默认每页显示几条数据</wbr>
<wbr> $fenyePage-&gt;everyPageRows =10;</wbr>
<wbr> //默认翻页页数</wbr>
<wbr>$fenyePage-&gt;pageWhole=10;</wbr>
<wbr> //</wbr>
$userServie = new userService();
$userServie->getFenYePage($fenyePage);<wbr></wbr>
for($i=0;$i<count($fenyePage->fenyeArray);$i++){
<wbr> $row =$fenyePage-&gt;fenyeArray[$i];</wbr>
echo "<tr align='center'height='25px'>";
echo"<td>$row[0]</td>";
echo"<td>$row[1]</td>";
echo"<td>$row[2]</td>";
echo"<td>$row[3]</td>";
echo"<td>$row[4]</td>";
echo"<td>$row[5]</td>";
echo "<td><ahref='#'>修改</a>&nbsp;||&nbsp;<ahref='#'>删除</a></td>";
echo "</tr>";
<wbr> }</wbr>
<wbr> ?&gt;</wbr>
</table><?php$fenyePage->showNavigate();?>
</body>
</html>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-355170-1-1.html 上篇帖子: PHP笔试题2 下篇帖子: ASP JSP PHP比较
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表