直接进入主题吧!可能不是最好的,但相信自己是自己做的会是最棒的,^_^
首先建一个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><<</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>>></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>友友管理 >友友信息</p>
<hr />
<table width="725" border="1" cellspacing="0"cellpadding="0" style="border-collapse:collapse"bordercolor="#6699CC">
<wbr> <trbgcolor="#6699cc"></wbr>
<wbr><wbr> <thscope="col">姓名</th></wbr></wbr>
<wbr><wbr> <thscope="col">性别</th></wbr></wbr>
<wbr><wbr> <thscope="col">专业</th></wbr></wbr>
<wbr><wbr> <thscope="col">Email</th></wbr></wbr>
<wbr><wbr> <thscope="col">籍贯</th></wbr></wbr>
<wbr><wbr> <thscope="col">电话</th></wbr></wbr>
<wbr><wbr> <thscope="col">操&nbsp;作</th></wbr></wbr>
<wbr> </tr></wbr>
<wbr><?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->nowPage =1;</wbr>
<wbr> if(!empty($_GET['nowPage'])){</wbr>
<wbr> $fenyePage->nowPage =$_GET['nowPage'];</wbr>
<wbr> }</wbr>
<wbr> //设置默认每页显示几条数据</wbr>
<wbr> $fenyePage->everyPageRows =10;</wbr>
<wbr> //默认翻页页数</wbr>
<wbr>$fenyePage->pageWhole=10;</wbr>
<wbr> //</wbr>
$userServie = new userService();
$userServie->getFenYePage($fenyePage);<wbr></wbr>
for($i=0;$i<count($fenyePage->fenyeArray);$i++){
<wbr> $row =$fenyePage->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> || <ahref='#'>删除</a></td>";
echo "</tr>";
<wbr> }</wbr>
<wbr> ?></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