php 生成翻页链接(页码)列表的函数
php中文网
发布时间:2016-07-25 09:00:37
|
1182人浏览过
|
来源于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)
- {
- return '';
- }
- if($element_total_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
- {
- if(intval($i) == intval($current_page))
- $page_num_string .= ''.$i.'';
- else
- $page_num_string .= ''.$i.'';
- }
-
- /* 上下翻页 */
- $prev_page = (intval($current_page-1)>0)?intval($current_page-1):0;
- $next_page = (intval($current_page)
- if(!empty($up_down_class))
- $up_down_class_str = ' class="'.$up_down_class.'"';
- else
- $up_down_class_str = '';
-
- $page_up_string = '';
-
- if(intval($prev_page) > 0)
- $page_up_string = '上一页';
- else
- $page_up_string = '上一页';
- $page_down_string = '';
-
- if(intval($next_page) > 0)
- $page_down_string .= '下一页';
- else
- $page_down_string .= '下一页';
- /* 返回结果 */
- return $page_up_string . $page_num_string . $page_down_string;
- }
- ?>
复制代码
|
PHP速学教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
下载
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
文心一言
文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。
讯飞写作
基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿
即梦AI
一站式AI创作平台,免费AI图片和视频生成。
ChatGPT
最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。