PHP页面分页函数
2009-09-12 22:52
211 查看
很久前些的一些文章,那时候技术还在初级阶段,在现在看来代码够烂的,但是人总是一步步走上来的,希望能给初学者一点鼓励了!
<?php
/*********************************************************
filename:multi.php
describe: 显示多于一页的链接
function:分页显示模块
author: etongchina@gmail.com
checked: 2008-02-15 18:05
调用方式:
$num:数据库总记录数
$perpage:每页显示条数
$curr_page:当前页码
$mpurl:链接的URL
$type:url改写后的链接
默认规则为:当前页码.htm
*********************************************************/
function multi($num, $perpage, $curr_page, $mpurl,$type = 0) {
$multipage = '';
if(!is_numeric($curr_page) || ( $curr_page < 1 )){
showmessage("无效页面参数!");
//自定义的输出提示函数
}
if($type == 1){
$script = '';
}else{
$script = ".htm";
}
if($num > $perpage) {
$page = 6;
$offset = 2;
$pages = ceil($num / $perpage);
if($curr_page > $pages){
showmessage("您查看的页面不存在!");
}
$from = $curr_page - $offset;
$to = $curr_page + $page - $offset - 1;
if($page > $pages) {
$from = 1; $to = $pages;
}else{
if($from < 1) {
$to = $curr_page + 1 - $from;
$from = 1;
if(($to - $from) < $page && ($to - $from) < $pages) {
$to = $page;
}
}elseif($to > $pages) {
$from = $curr_page - $pages + $to;
$to = $pages;
if(($to - $from) < $page && ($to - $from) < $pages) {
$from = $pages - $page + 1;
}
}
}
$start = ($curr_page-1)*$perpage+1;
if($curr_page == $pages){
$other = ($num%$perpage)?($num%$perpage):$perpage;
$end = ($curr_page-1)*$perpage+$other;
}else{
$end = $curr_page*$perpage;
}
$multipage .='<table border="0" cellspacing="1" cellpadding="3"><form name="multi">';
$multipage
.='<tr><td>【第<font
color="red">'.$start.'</font>-<font
color="red">'.$end.'</font>条,共'.$num.'条】
页码:<b>'.$curr_page.'</b> [共 <b>'.$pages.'</b>
页]:</td>';
$multipage .= ($curr_page - 1 >
$offset)?'<td width="30" align=center><a
href="'.$mpurl.'1'.$script.'" title="首页">首页</a></td>':'';
$multipage .= ($curr_page > 1)?'<td width="20"
align=center><a href="'.$mpurl.($curr_page - 1).$script.'"
title="上一页"><<</a></td>':"";
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= '<td width="8" align=center><a href="'.$mpurl.$i.$script.'">'.$i.'</a></td>';
} else {
$multipage
.= '<td width="8" align=center><font
color=red><u><b>'.$i.'</b></u></font></td>';
}
}
if($pages > $curr_page){
$multipage
.= '<td width="20" align=center><a href="'.$mpurl.($curr_page
+ 1).$script.'" title="下一页"> >></a></td>';
}
if($pages - $curr_page + $offset >= $page){
$multipage
.= '<td align=center width="30"><a
href="'.$mpurl.$pages.$script.'" title="尾页">尾页</a></td>';
}
$multipage .='<td><input style="WIDTH: 30px; HEIGHT: 16px" value=1 name=page>
</font>页<input type="button" value="GO"
style="height:22px;line-height:18px"
onclick="javascript:gotourl(/''.$mpurl.'/')"></td>';
$multipage .= "</tr></form></table>";
$multipage
.= "<script>function gotourl(inurl){ add =
multi.page.value+'".$script."';inurl = inurl+add;location.href=inurl;
}</script>";
}
return $multipage;
}
?>
<?php
/*********************************************************
filename:multi.php
describe: 显示多于一页的链接
function:分页显示模块
author: etongchina@gmail.com
checked: 2008-02-15 18:05
调用方式:
$num:数据库总记录数
$perpage:每页显示条数
$curr_page:当前页码
$mpurl:链接的URL
$type:url改写后的链接
默认规则为:当前页码.htm
*********************************************************/
function multi($num, $perpage, $curr_page, $mpurl,$type = 0) {
$multipage = '';
if(!is_numeric($curr_page) || ( $curr_page < 1 )){
showmessage("无效页面参数!");
//自定义的输出提示函数
}
if($type == 1){
$script = '';
}else{
$script = ".htm";
}
if($num > $perpage) {
$page = 6;
$offset = 2;
$pages = ceil($num / $perpage);
if($curr_page > $pages){
showmessage("您查看的页面不存在!");
}
$from = $curr_page - $offset;
$to = $curr_page + $page - $offset - 1;
if($page > $pages) {
$from = 1; $to = $pages;
}else{
if($from < 1) {
$to = $curr_page + 1 - $from;
$from = 1;
if(($to - $from) < $page && ($to - $from) < $pages) {
$to = $page;
}
}elseif($to > $pages) {
$from = $curr_page - $pages + $to;
$to = $pages;
if(($to - $from) < $page && ($to - $from) < $pages) {
$from = $pages - $page + 1;
}
}
}
$start = ($curr_page-1)*$perpage+1;
if($curr_page == $pages){
$other = ($num%$perpage)?($num%$perpage):$perpage;
$end = ($curr_page-1)*$perpage+$other;
}else{
$end = $curr_page*$perpage;
}
$multipage .='<table border="0" cellspacing="1" cellpadding="3"><form name="multi">';
$multipage
.='<tr><td>【第<font
color="red">'.$start.'</font>-<font
color="red">'.$end.'</font>条,共'.$num.'条】
页码:<b>'.$curr_page.'</b> [共 <b>'.$pages.'</b>
页]:</td>';
$multipage .= ($curr_page - 1 >
$offset)?'<td width="30" align=center><a
href="'.$mpurl.'1'.$script.'" title="首页">首页</a></td>':'';
$multipage .= ($curr_page > 1)?'<td width="20"
align=center><a href="'.$mpurl.($curr_page - 1).$script.'"
title="上一页"><<</a></td>':"";
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= '<td width="8" align=center><a href="'.$mpurl.$i.$script.'">'.$i.'</a></td>';
} else {
$multipage
.= '<td width="8" align=center><font
color=red><u><b>'.$i.'</b></u></font></td>';
}
}
if($pages > $curr_page){
$multipage
.= '<td width="20" align=center><a href="'.$mpurl.($curr_page
+ 1).$script.'" title="下一页"> >></a></td>';
}
if($pages - $curr_page + $offset >= $page){
$multipage
.= '<td align=center width="30"><a
href="'.$mpurl.$pages.$script.'" title="尾页">尾页</a></td>';
}
$multipage .='<td><input style="WIDTH: 30px; HEIGHT: 16px" value=1 name=page>
</font>页<input type="button" value="GO"
style="height:22px;line-height:18px"
onclick="javascript:gotourl(/''.$mpurl.'/')"></td>';
$multipage .= "</tr></form></table>";
$multipage
.= "<script>function gotourl(inurl){ add =
multi.page.value+'".$script."';inurl = inurl+add;location.href=inurl;
}</script>";
}
return $multipage;
}
?>
相关文章推荐
- php分页函数完整实例代码
- 使用相关函数实现PHP处理分页
- PHP 抓取html页面内容 函数
- 简单实用的分页函数(Php+mysql)
- php分页函数示例代码(转)
- PHP动态分页函数,PHP开发分页必备啦
- php页面缓存ob系列函数介绍
- PHP 长文章分页函数 带使用方法,不会分割段落,翻页在底部
- PHP获取当前页面URL函数实例
- PHP封装分页函数实现文本分页和数字分页
- 分页函数及应用(PHP)
- php分页函数
- php与html页面交互的几个函数
- 网上的一个PHP分页函数,测试可用
- 获取php页面执行时间,数据库读写次数,函数调用次数等(THINKphp)
- 关于php页面最大执行时间问题(set_time_limit函数在windows下不起作用的解决)
- PHP ceil() 函数(分页时很方便)
- Atitit.列表页面and条件查询的实现最佳实践(2)------翻页 分页 控件的实现java .net php
- php禁止页面缓存的函数
- PHP分页函数,最佳分页函数,版本2011-09-25 (备份)