PHP分页技术通用模版

直接进入主题吧!可能不是最好的,但相信自己是自己做的会是最棒的,^_^

首先建一个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 "<ul class='fenye_ul'>";
echo "<li>共{$this->sumPage}页</li>";
echo "<a href='userList.php?nowPage=1'><li>首页</li></a>";
if($this->nowPage>1){echo "<a href='userList.php?nowPage=".($this->nowPage-1)."'><li class='btn'>上页</li></a>";}
//翻页
$startPage = floor(($this->nowPage-1)/$this->pageWhole) * $this->pageWhole + 1;
$index = $startPage;
//如果当前页是在1到10之间,就没有必要显示向前翻页的链接
if($this->nowPage > $this->pageWhole){echo "<a href='userList.php?nowPage=".($startPage-1)."'><li><b>&lt;&lt;</b></li></a>";}
for(;$startPage<$index + $this->pageWhole;$startPage++){
if($startPage == $this->nowPage){
echo "<a href='userList.php?nowPage=$startPage'><li style='background:#6699cc;'>$startPage</li></a>";
}else{
echo "<a href='userList.php?nowPage=$startPage'><li>$startPage</li></a>";
}
}
//如果startPage的值小于总的页数,就显示向后翻译
if($startPage<$this->sumPage){echo "<a href='userList.php?nowPage=$startPage'><li><b>&gt;&gt;</b></li></a>";}
if($this->nowPage<$this->sumPage){echo "<a href='userList.php?nowPage=".($this->nowPage+1)."'><li>下页</li></a>";}
echo "<a href='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) or die(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 = "select user_name,user_gender,user_professional,user_email,user_addr,user_phone from 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.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="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;tr bgcolor="#6699cc"&gt;</wbr>
<wbr><wbr> &lt;th scope="col"&gt;姓名&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;th scope="col"&gt;性别&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;th scope="col"&gt;专业&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;th scope="col"&gt;Email&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;th scope="col"&gt;籍贯&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;th scope="col"&gt;电话&lt;/th&gt;</wbr></wbr>
<wbr><wbr> &lt;th scope="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><a href='#'>修改</a>&nbsp;||&nbsp;<a href='#'>删除</a></td>";
echo "</tr>";
<wbr> }</wbr>
<wbr> ?&gt;</wbr>
</table><?php $fenyePage->showNavigate();?>
</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值