클래식 PHP 페이징 코드

WBOY
풀어 주다: 2016-07-25 08:52:35
원래의
1011명이 탐색했습니다.
  1. /**************************************
  2. 파일: class.paging.php
  3. php 페이지네이션 클래스 코드
  4. *******************************************/
  5. 클래스 페이징{
  6. var $sql_results;
  7. var $sql_query;
  8. var $display_offset;
  9. var $display_limit;
  10. var $display_limit_URI;
  11. var $display_currentpage;
  12. var $display_totalpages;
  13. var $alt_content_count;
  14. var $display_offset_var;
  15. var $display_limit_var;
  16. var $display_mid_offset;
  17. var $display_link_first;
  18. var $display_link_prev;
  19. var $display_link_next;
  20. var $display_link_last;
  21. var $page_filename;
  22. var $page_uri;
  23. var $content;
  24. var $content_type;
  25. var $content_count;
  26. ## CONSTRUCTOR
  27. 함수 페이징($offsetVar='offset',$limit=10,$midOffset=2){
  28. $this->display_offset = isset($_REQUEST[$offsetVar])?$_REQUEST[ $offsetVar]:0;
  29. $this->display_limit = is_numeric($limit)?$limit:10;
  30. $this->display_mid_offset = $midOffset;
  31. $this->display_offset_var = $offsetVar;
  32. $this->display_currentpage= ceil($this->display_offset / $this->display_limit);
  33. }
  34. ## 데이터 처리
  35. 함수 setContent( $content){
  36. if( is_array($content) )
  37. $this->content_type = '배열';
  38. $this->content = $content;
  39. $this ->private_contentDetails();
  40. $this->getLinks();
  41. }
  42. function private_contentDetails(){
  43. if( $this->content_type == 'array' )
  44. $this->content_count = count($this->content);
  45. }
  46. function getContent(){
  47. $returnAry = array();
  48. for (
  49. $i=$this->display_offset;
  50. $i< min( $this->content_count, $this->display_offset $this->display_limit );
  51. $i
  52. )
  53. array_push($returnAry,$this->content[$i] );
  54. return $returnAry;
  55. }
  56. ## 탐색 링크
  57. function getLinks(){
  58. $this->getNextLink('');
  59. $this->getFirstLink('');
  60. $this->getLastLink('');
  61. $this->getPrevLink('');
  62. }
  63. function getNext(){
  64. return $this->display_link_next;
  65. }
  66. function getPrev(){
  67. return $this->display_link_prev;
  68. }
  69. 함수 getFirst(){
  70. return $this->display_link_first;
  71. }
  72. function getLast(){
  73. return $this->display_link_last;
  74. }
  75. function getNextLink($caption){
  76. // 콘텐츠를 계산하고 있는지 아니면 대체 사용자가 제공한 개수를 계산하는지 확인
  77. if( $this->alt_content_count )
  78. $count = $this ->alt_content_count;
  79. else
  80. $count = $this->content_count;
  81. if( $this->display_offset $this->display_limit-$count >=0 ) {
  82. $this->display_link_next = $this->display_offset;
  83. }else{
  84. $this->display_link_next = min(
  85. $count-1,
  86. $this->display_offset $this->display_limit
  87. );
  88. }
  89. return $this->buildLink( $this->buildNewURI( $this->display_link_next), $caption ) ;
  90. }
  91. 함수 getPrevLink($caption){
  92. $this->display_link_prev = max(
  93. 0,
  94. $this->display_offset-$this-> display_limit
  95. );
  96. return $this->buildLink( $this->buildNewURI( $this->display_link_prev), $caption );
  97. }
  98. function getFirstLink($ caption){
  99. $this->display_link_first = 0;
  100. return $this->buildLink( $this->buildNewURI( $this->display_link_first), $caption );
  101. }
  102. function getLastLink($caption){
  103. $this->display_link_last = $this->content_count-$this->display_limit;
  104. return $this->buildLink( $this- >buildNewURI( $this->display_link_last), $caption );
  105. }
  106. ## NUMBERS
  107. function getPageCount(){
  108. if( $this->alt_content_count )
  109. $count = $this->alt_content_count;
  110. else
  111. $count = $this->content_count;
  112. $this->display_totalpages = ceil(
  113. $count / $this->display_limit
  114. );
  115. return $this->display_totalpages;
  116. }
  117. function getPageNumbers(){
  118. // 변수 정의
  119. $midOffset = $this->display_mid_offset;
  120. $firstLink = $this->display_link_first;
  121. $pageCount = $this->getPageCount();
  122. $thisPage = $this->display_currentpage;
  123. $limit = $this->display_limit;
  124. $displayed=$midOffset*2 1;
  125. $returnAry=array();
  126. // dots
  127. $returnAry['afterdot'] = '';
  128. $returnAry['beforedot'] = '';
  129. // 두 번이고 중앙에 있는 경우 숫자가 모든 페이지를 합친 것보다 작습니다
  130. if( ($midOffset*2 1) < $pageCount ){
  131. $min = max($firstLink ,$thisPage-$midOffset);
  132. $max = min($pageCount,$thisPage $midOffset 1);
  133. $total = $max-$min;
  134. // x 금액을 유지합니다. 페이지 수
  135. // 1페이지 또는 2페이지의 중간에 있지 않은 경우에도 표시됩니다
  136. if($total<$displayed){
  137. if($min==0){
  138. $max =$displayed-$total;
  139. }
  140. if($max==$pageCount){
  141. $min-=$displayed-$total;
  142. }
  143. }
  144. }else{
  145. # 숫자 집합만 출력
  146. $min = 0;
  147. $max = $pageCount;
  148. }
  149. // 페이지 실행, 현재 페이지를 확인하고 이름을
  150. for($i=$min;$i<$max; $i){
  151. $cp = '아니요';
  152. if($thisPage==$i)
  153. $cp = '예';
  154. if($max!=$pageCount )
  155. $returnAry['afterdot'] = '...';
  156. if($min>0)
  157. $returnAry['beforedot'] = '...';
  158. array_push($returnAry,
  159. array(
  160. 'currentPage'=>$cp,
  161. 'pageNumber'=>($i 1),
  162. 'pageLink'=> $this->buildLink( $this->buildNewURI( ($i*$limit) ), ($i 1) )
  163. )
  164. );
  165. }
  166. $ 반환 returnAry;
  167. }
  168. function makePageNumbers($format, $pages,$boldCurrent=true,$separator=' '){
  169. $retPages = '';
  170. // 실제 페이지 번호 만들기
  171. foreach($pages as $key => $value):
  172. if(is_numeric($key))
  173. $retPages .= ('yes'==$value ['currentPage'] && $boldCurrent)?''.$value['pageLink'] .''.$separator:$value['pageLink'].$separator;
  174. endforeach;
  175. $format = str_replace( array('{beforedot}',
  176. '{afterdot}',
  177. '{pages}',
  178. '{separator}'),
  179. array( $pages['beforedot'],
  180. $pages['afterdot'],
  181. $retPages),
  182. $format);
  183. return $format;
  184. }
  185. ## 확인
  186. function isFirstPage(){
  187. if($this->display_currentpage==0)
  188. return true;
  189. return false;
  190. }
  191. function isLastPage(){
  192. // 기저가 1이 아니라 0이므로 하나 추가
  193. if($this->display_currentpage 1==$this->getPageCount())
  194. return true;
  195. return false;
  196. }
  197. ## 함수
  198. function getPageName(){
  199. $fileName =Explode('/',$_SERVER['REQUEST_URI']);
  200. $fileName = $fileName[count($fileName)-1];
  201. if(strpos($fileName,'?')>0) {
  202. $fileName = 폭발('?',$fileName) ;
  203. $fileName = $fileName[0];
  204. }
  205. return $fileName;
  206. }
  207. function getCleanURI(){
  208. $URI = $_SERVER ['REQUEST_URI'];
  209. if(strpos($URI,'?')>0){
  210. $URI = 폭발('?',$URI);
  211. $URI = $URI[ 1];
  212. $URI = preg_replace('/b'.$this->display_offset_var.'b[=0-9&]{2,20}/','',$URI);
  213. //$URI = preg_replace('/b'.$this->display_limit_var.'b[=0-9&]{2,20}/','',$URI);
  214. return $URI;
  215. }
  216. false 반환;
  217. }
  218. function buildNewURI($offset){
  219. $newFile = $this->getPageName() . '?' . $this->getCleanURI();
  220. $lastChar = substr($newFile,strlen($newFile)-1,1);
  221. if( $lastChar != '&' && $lastChar ! = '?' )
  222. $newFile.='&';
  223. $newFile .= $this->display_offset_var.'='.$offset.'&';
  224. //$ newFile .= $this->display_limit_var.'='.$limit.'&';
  225. return $newFile;
  226. }
  227. function buildLink( $href, $caption, $target=NULL ){
  228. if( $target != NULL )
  229. $target = ' target="'.$target.'"';
  230. return ''.$caption.'';
  231. }
  232. 함수 encodeURI($str){
  233. $salt = 'falaful ';
  234. $str = strrev($salt.$str);
  235. return base64_encode($str);
  236. }
  237. 함수 decodeURI($str){
  238. $salt = 'falaful';
  239. $str = strrev( base64_decode($str) );
  240. $str = substr( $str, strlen($salt), strlen($str) );
  241. return $str;
  242. }
  243. #############
  244. #
  245. #이 함수는 이
  246. #클래스를 실행할 쿼리를 입력하는 데 사용됩니다. 다른 함수는
  247. #x개의 행을 모두 가져온 다음 잘라냅니다. 이러한 기능은
  248. #한도만큼만 제한됩니다. 이렇게 하면 성능이 향상됩니다.
  249. #이유는 3을 원할 때 1,000,000개의 행을 가져오지 않기 때문입니다.
  250. #
  251. #############
  252. 함수 runWQuery ($db, $statement, $table, $where=''){
  253. // 총 행 가져오기
  254. $db->query( 'SELECT COUNT(*) AS count FROM '. $ 테이블 . ' ' . $where );
  255. $db->movenext();
  256. $this->alt_content_count = $db->col['count'];
  257. / / 쿼리에 제한을 추가합니다
  258. $where .= ' LIMIT ' . $this->display_offset .', '.$this->display_limit;
  259. // 쿼리 저장
  260. $this->sql_query = $statement . ' 에서 ' . $테이블 .' '. $where;
  261. // 쿼리 인쇄
  262. //echo $this->sql_query;
  263. // 쿼리 실행
  264. $db->query( $this-> ;sql_query );
  265. $this->sql_results = array();
  266. // 결과 저장
  267. while($db->movenext()){
  268. array_push($this ->sql_results , $db->col);
  269. }
  270. return $this->runQueryActions();
  271. }
  272. function runQueryActions(){
  273. $this->setContent( $this->sql_results );
  274. $pages = $this->getPageNumbers();
  275. // 실제 페이지 번호 만들기
  276. $ retPages = $this->makePageNumbers( '{beforedot} {pages} {afterdot}', $pages, true, ' ' );
  277. // 새 디스플레이 가져오기
  278. return 배열(
  279. 'content'=>$this->sql_results,
  280. 'pages'=>$retPages
  281. );
  282. }
  283. }
  284. ?>
复제대码


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