PHP 페이징 클래스 코드, 사용자 정의 가능한 매개변수 PHP 페이징 코드

WBOY
풀어 주다: 2016-07-25 08:52:34
원래의
831명이 탐색했습니다.
  1. class PageLink {

  2. /* 페이징 표시 매개변수 설정*/
  3. private $db_table = "";
  4. private $db_table_field = ""; //표시할 데이터베이스의 필드
  5. private $condition = ""; //쿼리 조건
  6. private $sort = "" //정렬 조건
  7. private $page_size = 0; //각 페이지에 표시되는 레코드 수
  8. private $link_num = 0; //표시되는 페이지 번호 링크 수
  9. private $page = 1 //현재 페이지 번호
  10. private $records = 0 ; // 테이블의 총 레코드 수
  11. private $page_count = 0; //총 페이지 수
  12. private $pagestring = "" //
  13. private $linkUrl = ""; //현재 페이지 경로
  14. private $urlPara = ""; //현재 페이지 url 매개변수
  15. private $linkUrlNum = 1;
  16. /*
  17. * 사용자 정의 페이징
  18. */
  19. private $linkFormat = " ";

  20. /* 가져온 데이터*/

  21. private $page_data = "";//데이터베이스에서 가져온 데이터,

  22. //$page_data를 2차원 배열로 받았습니다

  23. private $dbHelper;

  24. /* 변수 정의 부분 end */

  25. /* 함수 정의(클래스 메소드) 시작 */

  26. function __construct() {include_once 'DBHelper/DBHelper.php';//데이터베이스입니다 연산 클래스

  27. $this- >dbHelper = new DBHelper();
  28. }

  29. /*

  30. * 페이징 정보 설정 시작
  31. * @param $ db_table 테이블
  32. * @param $db_table_field 필드
  33. * @param $condition 조건
  34. * @param $sort 정렬
  35. * @param $page_size 표시 번호
  36. * @param $link_num 숫자 개수 links
  37. * @param $url 페이지 경로
  38. * @param $para url 매개변수
  39. */
  40. 공용 함수 집합($db_table, $db_table_field, $condition, $sort, $page_size, $link_num , $url, $para) {
  41. $this->db_table = $db_table;//테이블 이름
  42. $this->db_table_field = $db_table_field; //필드 배열,
  43. $this-> ;condition = $condition; //정렬 조건
  44. $this->sort = $sort; //정렬 조건
  45. //표시할 필드 이름
  46. //배열에 쓰기
  47. / * db 파라미터 설정 종료 */< ;/p>
  48. /* 페이징 파라미터 설정 시작 */

  49. $this->page_size = $page_size;//각 페이지에 표시되는 레코드 수
  50. $this->link_num = $link_num;//페이지 넘김 링크 수 표시
  51. $this->linkUrl = $url;
  52. $this->urlPara = $para;
  53. /* 페이징 매개변수 설정 end */
  54. }

  55. /* 페이징 정보 설정 end */>

  56. /* 페이징 링크 가져오기 데이터 시작 */

  57. public function get() {

  58. $page_data[0] = $this->pagestring;
  59. $page_data[1] = $this- >page_data;
  60. return $page_data;
  61. }

  62. /* 페이지 매기기 링크 데이터 가져오기 end */

  63. /* 페이지 번호 처리 시작 */

  64. private function set_page() {

  65. if (isset($_REQUEST["page"])) {
  66. $this->page = intval($_REQUEST["page"]);
  67. } else {
  68. $this->page = 1;
  69. }
  70. }

  71. /* 페이지 번호 처리 끝 */

  72. /* DB의 레코드 수 가져오기 시작 */

  73. private function get_records() {

  74. $this->records = $this-> ;dbHelper->counts($this->db_table, $this->condition);
  75. }

  76. < p>/* dbend의 레코드 수 가져오기 */

  77. /* 페이지 링크 문자열 만들기 시작 */

  78. 개인 함수 page_link( ) {

  79. $checkPage = intval($this ->page / $this->link_num);
  80. $startPage = 1;
  81. $stopPage = 1;
  82. if($checkPage == 0 && $this->페이지 < $this ->link_num){
  83. $startPage = 1;
  84. }
  85. $linkPage = ($this->link_num / 2);
  86. if($this->page > $linkPage ){
  87. $startPage = $this->page - $linkPage;
  88. }
  89. if(($startPage $this->link_num)> ;$this->page_count){
  90. $startPage = $this->page_count - $this->link_num 1;
  91. }
  92. if($startPage<1){
  93. $startPage = 1;
  94. }
  95. $stopPage = $startPage ($this->link_num - 1);
  96. if($stopPage> $this->page_count){
  97. $stopPage = $this ->page_count;
  98. }
  99. $countStr = "共".$this->records."條記錄";
  100. $currStr = "".$this->page."/" .$this->page_count."頁 ";
  101. $beginLink = "首頁";
  102. $preLink = "上一頁";
  103. $nextLink = "下一頁";
  104. $noPreLink = "上一頁 ";
  105. $noNextLink = "下一頁";
  106. $endLink = "尾頁";
  107. if($this->page > ($linkPage 1) && $this- >page_count > $this->link_num){
  108. $currPage .= "1";
  109. }
  110. for($i=$startPage;$i<=$stopPage;$i ){
  111. if($i == $this-> ;페이지){
  112. $currPage .= "".$i."";
  113. }
  114. else{
  115. $currPage . = "".$i."";
  116. }
  117. }
  118. if(($this->page_count - $this->page) > $linkPage && $this->page_count > $this->link_num){
  119. $currPage .= "...".$this->page_count."";
  120. }
  121. $jumpPage .= "< ;입력 유형='텍스트' id='page_text_".$this->linkUrlNum.
  122. "' onmouseover='select();' size='1' maxlength='4' onkeyup="this.value=this.value.replace(/\D /g,'');" /> ";
  123. $jumpPage .= "< ;입력 유형='버튼' onclick="window.location.href='".$this->linkUrl
  124. ."?page=' document.getElementById('page_text_".$this->linkUrlNum." ').value '".$this->urlPara
  125. ."'" name='page_submit' value='GO' />";
  126. $this->linkUrlNum ;
  127. if( !empty($this->linkFormat)){
  128. $tempLinkFormat = $this->linkFormat;
  129. $tempLinkFormat = str_replace("總記錄", $countStr, $tempLinkFormat);
  130. $tempLinkFormat = str_replace("頁次", $currStr, $tempLinkFormat);
  131. if($this->page_count > 1){
  132. $tempLinkFormat = str_replace("首頁", $beginLink, $tempLinkFormat);
  133. if($this->page > 1){
  134. $tempLinkFormat = str_replace("上一頁", $preLink, $tempLinkFormat);
  135. }
  136. else{
  137. $ tempLinkFormat = str_replace("上一頁", $noPreLink, $tempLinkFormat);
  138. }
  139. if($this->page < $this->page_count){
  140. $tempLinkFormat = str_replace( "下一頁", $nextLink, $tempLinkFormat);
  141. }
  142. else{
  143. $tempLinkFormat = str_replace("下一頁", $noNextLink, $tempLinkFormat);
  144. }
  145. $tempLinkFormat = str_replace("尾頁", $endLink, $tempLinkFormat);
  146. $tempLinkFormat = str_replace("分頁", $currPage, $tempLinkFormat);
  147. $tempLinkFormat = str_replace("跳轉", $jumpPage , $tempLinkFormat);
  148. }
  149. else{
  150. $tempLinkFormat = str_replace("首頁", "", $tempLinkFormat);
  151. $tempLinkFormat = str_replace("上一頁", "", $tempLinkFormat);
  152. $tempLinkFormat = str_replace("下一頁", "", $tempLinkFormat);
  153. $tempLinkFormat = str_replace("尾頁", "", $tempLinkFormat);
  154. $tempLinkFormat = str_replace("分頁", "", $tempLinkFormat);
  155. $tempLinkFormat = str_replace("跳轉", "", $tempLinkFormat);
  156. }

  157. }

  158. $this->pagestring.=$countStr." ".$currStr;
  159. if($this->page_count > 1){
  160. $this->pagestring.=$beginLink;
  161. if($this->page > 1){
  162. $this->pagestring.=$preLink;
  163. }
  164. $this->pagestring.=$currPage;
  165. if($this->page < $this->page_count){
  166. $this->pagestring.=$nextLink;
  167. }
  168. $this->pagestring.=$endLink.$jumpPage;
  169. }
  170. }
  171. /* 페이지 넘김 링크 문자열 만들기 end */

  172. /* 데이터 가져오기 시작 */

  173. 비공개 함수 fetch_data() {

  174. if ($this->records) {
  175. $limit = ($this->page - 1) * $this->page_size ",$ this->page_size";
  176. $this->page_data = $this->dbHelper->fetch($this->db_table, $this->condition, $this->sort, $ 제한);
  177. }
  178. }

  179. /* 데이터 가져오기 끝 */

  180. /* 페이징 만들기 시작 */< ;/p>

  181. 공용 함수 create_page() {

  182. $this->set_page();
  183. $this->get_records();
  184. $this->page_count = ceil($this->records / $this->page_size);
  185. $this->page_link();
  186. $this->fetch_data();
  187. }
  188. /* 페이지 매김 생성 end */

  189. function __destruct() {

  190. }

  191. /* 함수 정의(클래스 메소드) end */

  192. }
  193. /*
  194. 호출 메소드
  195. include_once 'PageLink.php';
  196. $pageLink = new PageLink (); //인스턴스화된 객체
  197. $pageLink->set("table", "*(또는 필드)", "조건", "정렬", "데이터 항목 수", "페이지당 링크 수 " , "페이지(list.php)", "?page=1 (&id=1&name=test)"를 제외한 기타 매개변수");//수신 매개변수
  198. $pageLink->create_page();//페이징 생성
  199. $list = $pageLink->get();//데이터 가져오기
  200. echo $list[0];//페이징 링크
  201. print_r($list[1]) //데이터 인쇄, 또는 필요에 따라 반복
  202. */

코드 복사


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!