Home  >  Article  >  Backend Development  >  Brief analysis of PHP paging principle, simple example of PHP paging code

Brief analysis of PHP paging principle, simple example of PHP paging code

WBOY
WBOYOriginal
2016-07-25 08:52:451138browse
  1. $pages = range(1, 100); 记录数

  2. $page_list['end'] = (count($pages) / 10) ? ceil((count($pages) / 10)) : 0; //总页数 最后页数

  3. $step = isset($_GET['step']) ? $_GET['step'] : 5; //步长

  4. $curr_page = isset($_GET['curr_page']) ? $_GET['curr_page'] : 1; //当前页
  5. $page_list['first'] = 1; //首页
  6. $page_list['prev'] = max($curr_page - 1, 1); //上一页
  7. $page_list['now'] = min($curr_page, $page_list['end']); 当前页
  8. $page_list['next'] = min($curr_page + 1, $page_list['end']); //下一页
  9. $page_list['step_first'] = max(1, $page_list['now']-$step);
  10. $page_list['step_end'] = min($page_list['step_first']+$step, $page_list['end']);
  11. $page_list['step_list'] = range($page_list['step_first'], $page_list['step_end']);
  12. echo '第一页', '上一页';
  13. foreach ($page_list['step_list'] as $value) {
  14. echo '' . $value . '';
  15. }
  16. echo'下一页', '最后页

复制代码


Statement:
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