Blogger Information
Blog 40
fans 0
comment 0
visits 16087
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php封装分页函数
飞天001
Original
674 people have browsed it

分页自定义函数

  1. <?php
  2. /***
  3. * $page 当前页
  4. * $pageSize 每页显示条数
  5. * $pages 总页数
  6. */
  7. function page($page,$pageSize,$pages){
  8. $span=''; //定义空字符串
  9. $preStr =''; //上一页
  10. $nextStr= ''; //下一页
  11. for($i=1;$i<=$pages;$i++){
  12. $active=($page==$i)?'active':null;
  13. $span .= '<a class="'.$active.'" href="?p='.$i.'">'.$i.'</a>';
  14. }
  15. $prev = $page - 1;
  16. if($page<=1) $prev==1;
  17. if($page>1){
  18. $preStr = '<a href="?p='.$prev.'">上一页</a>';
  19. }
  20. $next = $page + 1;
  21. if($page>=$pages) $next=$pages;
  22. if($page<$pages){
  23. $nextStr ='<a href="?p='.$next.'">下一页</a>';
  24. }
  25. $span = $preStr.$span.$nextStr;
  26. return $span;
  27. }

在需要分页的页面, 获取参数值,偏移量在分页的页面设置.

  1. <?=page($page,$pageSize,$pages);?>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post