PHP paging class code example, paging class that can be used in the PHP framework

WBOY
Release: 2016-07-25 08:52:36
Original
899 people have browsed it
  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. * Get the parameters passed by get after the url
  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. * Get paginated 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 = $end<$this->pagenum ? $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<=$end;$i++){
  37. $pagestr.= "".$i." ";
  38. }
  39. if($this->page!=$this->pagenum){
  40. $pagestr.="下一页";
  41. }
  42. if($this->page+5<$this->pagenum){
  43. $pagestr.="尾页 ";
  44. }
  45. return $pagestr;
  46. } // edit: bbs.it-home.org
  47. }
  48. // 分页代码测试
  49. $page = new page(100,10);
  50. $str=$page->getPage();
  51. echo $str;
  52. ?>
复制代码


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!