Home > Backend Development > PHP Tutorial > 实现分十页分向前十页向后十页的处理

实现分十页分向前十页向后十页的处理

WBOY
Release: 2016-06-01 14:29:25
Original
1103 people have browsed it
 
/*====对数据的记录进行分页显示===== 
一张页面有连续的十个页面的连接 
一页可显示$limit_row条记录信息 
并有下十页和上十页翻页功能 
=================================== 

------需传入值$total_row;$limit_row;$pagename;----- 
$total_row为所选查询结果的总行数 
$limit_row为每页显示的最大行数 
$pagename为返回显示页面名称。(不带后缀名) 
---------------------------------------------------- 

---------------------------------------------------- 
$page当前所读页面 
$total_page为共可分为几页. 
$row_begin为从第几行开始读 
$row_end为读到第几行为止 
-----------------------------------------------------*/ 

if (!$page){ $page=1;} 
$total_page=ceil($total_row/$limit_row); 
$row_begin=$limit_row*($page-1); 
if($page==$total_page&&($total_row%$limit_row)){ 
$read_row=($total_row%$limit_row); 
}else{$read_row=$limit_row;} 
if($total_page $page_begin=0; 
$page_end=$total_page; 
$page10=1; 
$newpage10=1; 
}else{ 
//--------------分页显示下十页---------------- 
// $page10为总共有几个十页 
// $newpage10为读十页的起始位置 
// $page_endx为读取最后的页数 

$page10=ceil($total_page/10); 
if($newpage10 ==""){$newpage10=1;} 
$page_begin=10*($newpage10-1); 
if($newpage10==1) 
{ 
if($newpage10==($page10-1)&&($total_page%10)) 
{ 
$page_endx=$total_page%10; 
$page_end=10; 
echo "| 最前十页 | 下 $page_endx 页 |"; 
}else{ 
$page_end=10; 
echo "| 已是最前十页 | 下十页 |"; 
} 
}elseif($newpage10>1){ 
if($newpage10==$page10&&($total_page%10)) 
{$page_end=$total_page%10; 
echo "| 前十页 |已是最后 $page_end 页|"; 
}else{ 
if($newpage10==($page10-1)&&($total_page%10)) 
{ $page_endx=$total_page%10; 
$page_end=10; 
echo "| 前十页 | 下 $page_endx 页 |"; 
} else{ 
$page_end=10; 
echo "| 前十页 | 下十页 |"; 
} 
} 

} 
} 

//----------------------每十页页码-------------------------------------- 
echo "总共:".$total_row."条 第 "; 
for ($n=$page_begin+1;$n echo "$n "; 
} 
echo "页"; 

?>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template