#1 administrator
/** Created on 2009-12-20
*
*
*
*/
class Showpage{
function showpage(){
}
/***********************************************************
*$page_id 当前页面页码数
*$info_sum 信息总数
*$page_info_num 每页显示的信息条数
*$line_page_sum 页码行显示的页码个数
*$url 当前页面的url地址
**************************************************************/
function page($info_sum,$page_info_num,$line_page_sum,$page_id,$url){
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 通过信息总数和每页显示的信息数获取总页数
* $page_sum 页码总数
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
$page_temp = $info_sum%$page_info_num;
$page_temp_1 = floor($info_sum/$page_info_num);
$page_temp == 0?$page_sum = $page_temp_1:$page_sum = $page_temp_1+1;
//echo "总页数:".$page_sum."
规定每行显示的页码数:".$line_page_sum;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 如果当前页码数大于总页数则提示非法访问
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
if($page_id > $page_sum){
die("");
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 通过比较规定的每行显示页码数和总页码数得出每行显示的页码数
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
if($page_sum < $line_page_sum){
$line_page_sum = $page_sum;
}
//echo "
每行应该显示的页码数:".$line_page_sum;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 计算中间数和左偏移、右偏移
* $line_middle_num 中间数
* $left_p 左偏移数
* $right_P 右偏移数
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
if($line_page_sum % 2 == 0){
$line_middle_num = $line_page_sum/2;
$left_p = $line_middle_num - 1;
$right_p = $left_p + 1;
}else{
$line_middle_num = ($line_page_sum+1)/2;
$left_p = ($right_p = $line_middle_num - 1);
}
// echo "
中间数为:".$line_middle_num."
左偏移:".$left_p."
右偏移:".$right_p;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 判断通过当前id和中间数获取显示行的起始页码数和结束页码数
* $star_page 起始页码数
* $end_page 结束页码数
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
if($page_id <=$line_middle_num){
$star_page = 1;
$end_page = $line_page_sum;
}else{
if($left_p == 0){
$str_page = 1;
}else{
if($page_id+$right_p >= $page_sum){
$end_page = $page_sum;
$star_page = $end_page - $line_page_sum+1;
}else{
$star_page = $page_id - $left_p;
$end_page = $page_id + $right_p;
}
}
}
//echo "
起始页:".$star_page."
结束页:".$end_page."
";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 获取上一页、下一页连接
* $prev_page 上一页
* $next_page 下一页
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
if($page_id - 1 <= 0){
$prev_page = "上一页 ";
}else{
$prev_page = "上一页 ";
}
if($page_id + 1 > $page_sum){
$next_page = "上一页 ";
}else{
$next_page = "下一页 ";
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 循环输出页码数,并返回
* 并返回
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
$str = $prev_page;
for($i=$star_page;$i<=$end_page;$i++){
if($i == $page_id){
$str .= $i." ";
}else{
$str .="".$i." ";
}
}
$str .= $next_page;
return $str;
}
}
2009-12-24 09:29:00