php如何制作列表翻页,php 生成翻页链接(页码)列表的函数

完整代码如下。

复制代码 代码示例:

/**

* 生成页码列表

*

* @param int $element_total_count 元素总数

* @param int $current_page 当前页

* @param int $per_page_elem_count 每页元素数

* @param int $show_page_num 列表显示的页码数

* @param string $up_down_class 上下翻页样式

* @param string $num_class 当前页页码数字样式

* @param string $href 页面链接

* @param string $page_symbol 传递页码数的链接参数

* @return string

*/

function get_page_link_list($element_total_count,$current_page=1,$per_page_elem_count=10,$show_page_num=10,$up_down_class,$num_class,$href,$page_symbol='p')

{

if(empty($href))

{

//自动取得剔除页码参数的页面链接

$page_name = basename($_SERVER['PHP_SELF']);

$params = $_SERVER['QUERY_STRING'];

$params_str = '';

if(!empty($params))

{

$params = str_replace('&', '&', $params);

$params_array = explode('&', $params);

foreach($params_array as $param)

{

if(!empty($param))

{

$index = strpos($param, '=');

if($index)

{

$key = substr($param, 0, $index);

if($key && $key != $page_symbol)

$params_str .= $param . '&';

}

}

}

}

if(!empty($params_str))

$href = $page_name . '?' . $params_str;

else

$href = $page_name;

$href = rtrim($href,'&');

}

$prefix = strpos($href,"?") ? "&" : "?";

$prefix .= $page_symbol;

$page_total_count = ceil($element_total_count/$per_page_elem_count);

if(intval($element_total_count)< 1 || !isset($element_total_count))

{

return '';

}

if($element_total_count <= $per_page_elem_count)

return '';

if($current_page>$page_total_count)

$current_page = 1;

if(strpos($href,"#"))

{

$label = substr($href,strpos($href,"#"));

$href = substr($href,0,strpos($href,"#"));

}

/* 生成页码 */

if($current_page > ceil($show_page_num/2))

{

$start = $current_page - ceil($show_page_num/2);

$end = (($current_page+ceil($show_page_num/2))

$current_page+ceil($show_page_num/2)-1 : $page_total_count;

}

else

{

$start = 1;

$end = ($show_page_num>$page_total_count) ? $page_total_count : $show_page_num;

}

if(!empty($num_class))

$num_class_str = ' class="'.$num_class.'"';

else

$num_class_str = '';

$page_num_string = '';

for($i=$start;$i<=$end;$i++)

{

if(intval($i) == intval($current_page))

$page_num_string .= ''.$i.'';

else

$page_num_string .= '

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值