php分页类代码示例,可在php框架中使用的分页类

WBOY
发布: 2016-07-25 08:52:36
原创
900 人浏览过
  1. //php分页类代码
  2. class page{
  3. public $page; //当前页
  4. public $pagenum; // 页数
  5. public $pagesize; // 每页显示条数
  6. public function __construct($count, $pagesize){
  7. $this->pagenum = ceil($count/$pagesize);
  8. $this->pagesize = $pagesize;
  9. $this->page =(isset($_GET['p'])&&$_GET['p']>0) ? intval($_GET['p']) : 1;
  10. }
  11. /**
  12. * 获得 url 后面get传递的参数
  13. */
  14. public function getUrl(){
  15. $url = 'index.php?'.http_build_query($_GET);
  16. $url = preg_replace('/[?,&]p=(\w)+/','',$url);
  17. $url .= (strpos($url,"?") === false) ? '?' : '&';
  18. return $url;
  19. }
  20. /**
  21. * 获得分页html
  22. */
  23. public function getPage(){
  24. $url = $this->getUrl();
  25. $start = $this->page-5;
  26. $start=$start>0 ? $start : 1;
  27. $end = $start+9;
  28. $end = $endpagenum ? $end : $this->pagenum;
  29. $pagestr = '';
  30. if($this->page>5){
  31. $pagestr = "首页 ";
  32. }
  33. if($this->page!=1){
  34. $pagestr.= "上一页";
  35. }
  36. for($i=$start;$i $pagestr.= "".$i." ";
  37. }
  38. if($this->page!=$this->pagenum){
  39. $pagestr.="下一页";
  40. }
  41. if($this->page+5pagenum){
  42. $pagestr.="尾页 ";
  43. }
  44. return $pagestr;
  45. } // edit: bbs.it-home.org
  46. }
  47. // 分页代码测试
  48. $page = new page(100,10);
  49. $str=$page->getPage();
  50. echo $str;
  51. ?>
复制代码


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!