ホームページ >バックエンド開発 >PHPチュートリアル >簡単、便利、フル機能の PHP ページング クラス

簡単、便利、フル機能の PHP ページング クラス

WBOY
WBOYオリジナル
2016-06-13 12:53:191440ブラウズ
<p> シンプル、便利、フル機能の php ページング クラス<br></p> <div class="container"> <div class="line number1 index0 alt2"><code class="php plain"><code class="php plain"><br> 分页类代码<br> <?php </code> ページネーションクラスコード</p> <?php </code><div class="line number2 index1 alt1"> <code class="php keyword">class</code><code class="php plain"> SubPages{ </code> </p><div class="line number3 index2 alt2"> <code class="php spaces"> </code></p> <div class="line number4 index3 alt1"> <code class="php spaces"> </code><code class="php keyword">private</code><code class="php variable">$each_disNums</code> <code class="php plain">;</code><code class="php comments">//每页显示的条目数 </code></p><div class="line number5 index4 alt2"> <code class="php spaces"> </code><code class="php keyword">private</code><code class="php variable">$nums</code> <code class="php plain">;</code><code class="php comments">//总条目数 </code></p><div class="line number6 index5 alt1"> <code class="php spaces"> </code><code class="php keyword">private</code><code class="php variable">$current_page</code> <code class="php plain">;</code><code class="php comments">//当前被选中的页 </code></p><div class="line number7 index6 alt2"> <code class="php spaces"> </code><code class="php keyword">private</code><code class="php variable">$sub_pages</code> <code class="php plain">;</code><code class="php comments">//每次显示的页数 </code></p><div class="line number8 index7 alt1"> <code class="php spaces"> </code><code class="php keyword">private</code><code class="php variable">$pageNums</code> <code class="php plain">;</code><code class="php comments">//总页数 </code></p><div class="line number9 index8 alt2"> <code class="php spaces"> </code><code class="php keyword">private</code><code class="php variable">$page_array</code> <code class="php plain">= </code> <code class="php keyword">array</code><code class="php plain">();</code><code class="php comments">//用来构造分页的数组 </code></p><div class="line number10 index9 alt1"> <code class="php spaces"> </code><code class="php keyword">private</code><code class="php variable">$subPage_link</code> <code class="php plain">;</code><code class="php comments">//每个分页的链接 </code></p><div class="line number11 index10 alt2"> <code class="php spaces"> </code><code class="php keyword">private</code><code class="php variable">$subPage_type</code> <code class="php plain">;</code><code class="php comments">//显示分页的类型 </code></p><div class="line number12 index11 alt1"> <code class="php spaces"> </code><code class="php comments">/* </code></p><div class="line number13 index12 alt2"> <code class="php spaces"> </code><code class="php comments">__construct是SubPages的构造函数,用来在创建类的时候自动运行. </code></p><div class="line number14 index13 alt1"> <code class="php spaces"> </code><code class="php comments">@$each_disNums 每页显示的条目数 </code></p><div class="line number15 index14 alt2"> <code class="php spaces"> </code><code class="php comments">@nums 总条目数 </code></p><div class="line number16 index15 alt1"> <code class="php spaces"> </code><code class="php comments">@current_num 当前被选中的页 </code></p><div class="line number17 index16 alt2"> <code class="php spaces"> </code><code class="php comments">@sub_pages 每次显示的页数 </code></p><div class="line number18 index17 alt1"> <code class="php spaces"> </code><code class="php comments">@subPage_link 每个分页的链接 </code></p><div class="line number19 index18 alt2"> <code class="php spaces"> </code><code class="php comments">@subPage_type 显示分页的类型 </code></p><div class="line number20 index19 alt1"> <code class="php spaces"> </code></p> <div class="line number21 index20 alt2"> <code class="php spaces"> </code><code class="php comments">当@subPage_type=1的时候为普通分页模式 </code></p><div class="line number22 index21 alt1"> <code class="php spaces"> </code><code class="php comments">example: 共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页] </code></p><div class="line number23 index22 alt2"> <code class="php spaces"> </code><code class="php comments">当@subPage_type=2的时候为经典分页样式 </code></p><🎜><div class="line number24 index23 alt1"><code class="php spaces"> </code><code class="php comments">example: 当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页] </code></p> <div class="line number25 index24 alt2"><code class="php spaces"> </code><code class="php comments">*/</code> </p> <div class="line number26 index25 alt1"><code class="php spaces"> </code><code class="php keyword">function</code> <code class="php plain">__construct(</code><code class="php variable">$each_disNums</code><code class="php plain">,</code><code class="php variable">$nums</code><code class="php plain">,</code><code class="php variable">$current_page</code><code class="php plain">,</code><code class="php variable">$sub_pages</code><code class="php plain">,</code><code class="php variable">$subPage_link</code><code class="php plain">,</code><code class="php variable">$subPage_type</code><code class="php plain">){ </code></p> <div class="line number27 index26 alt2"><code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->each_disNums=</code><code class="php functions">intval</code><code class="php plain">(</code><code class="php variable">$each_disNums</code><code class="php plain">);  </code> <div class="line number28 index27 alt1"> <code class="php spaces">   </code><code class="php variable">$this</code><code class="php plain">->nums=</code><code class="php functions">intval</code><code class="php plain">(</code><code class="php variable">$nums</code><code class="php plain">);  </code> <div class="line number29 index28 alt2"> <code class="php spaces">    </code><code class="php keyword">if</code><code class="php plain">(!</code><code class="php variable">$current_page</code><code class="php plain">){  </code> <div class="line number30 index29 alt1"> <code class="php spaces">    </code><code class="php variable">$this</code><code class="php plain">->current_page=1;  </code> <div class="line number31 index30 alt2"> <code class="php spaces">    </code><code class="php plain">}</code><code class="php keyword">else</code><code class="php plain">{  </code> <div class="line number32 index31 alt1"> <code class="php spaces">    </code><code class="php variable">$this</code><code class="php plain">->current_page=</code><code class="php functions">intval</code><code class="php plain">(</code><code class="php variable">$current_page</code><code class="php plain">);  </code> <div class="line number33 index32 alt2"> <code class="php spaces">    </code><code class="php plain">}  </code> <div class="line number34 index33 alt1"> <code class="php spaces">   </code><code class="php variable">$this</code><code class="php plain">->sub_pages=</code><code class="php functions">intval</code><code class="php plain">(</code><code class="php variable">$sub_pages</code><code class="php plain">);  </code> <div class="line number35 index34 alt2"> <code class="php spaces">   </code><code class="php variable">$this</code><code class="php plain">->pageNums=</code><code class="php functions">ceil</code><code class="php plain">(</code><code class="php variable">$nums</code><code class="php plain">/</code><code class="php variable">$each_disNums</code><code class="php plain">);  </code> <div class="line number36 index35 alt1"> <code class="php spaces">   </code><code class="php variable">$this</code><code class="php plain">->subPage_link=</code><code class="php variable">$subPage_link</code><code class="php plain">;   </code> <div class="line number37 index36 alt2"> <code class="php spaces">   </code><code class="php variable">$this</code><code class="php plain">->show_SubPages(</code><code class="php variable">$subPage_type</code><code class="php plain">);   </code> <div class="line number38 index37 alt1"> <code class="php spaces">   </code><code class="php comments">//echo $this->pageNums."--".$this->sub_pages;  </code> <div class="line number39 index38 alt2"> <code class="php spaces">  </code><code class="php plain">}  </code> <div class="line number40 index39 alt1"> <code class="php spaces">    </code> <div class="line number41 index40 alt2"> <code class="php spaces">    </code> <div class="line number42 index41 alt1"> <code class="php spaces">  </code><code class="php comments">/* </code><div class="line number43 index42 alt2"> <code class="php spaces">    </code><code class="php comments">__destruct析构函数,当类不在使用的时候调用,该函数用来释放资源。 </code> <div class="line number44 index43 alt1"> <code class="php spaces">   </code><code class="php comments">*/</code> <div class="line number45 index44 alt2"> <code class="php spaces">  </code><code class="php keyword">function</code> <code class="php plain">__destruct(){  </code> <div class="line number46 index45 alt1"> <code class="php spaces">    </code><code class="php plain">unset(</code><code class="php variable">$each_disNums</code><code class="php plain">);  </code> <div class="line number47 index46 alt2"> <code class="php spaces">    </code><code class="php plain">unset(</code><code class="php variable">$nums</code><code class="php plain">);  </code> <div class="line number48 index47 alt1"> <code class="php spaces">    </code><code class="php plain">unset(</code><code class="php variable">$current_page</code><code class="php plain">);  </code> <div class="line number49 index48 alt2"> <code class="php spaces">    </code><code class="php plain">unset(</code><code class="php variable">$sub_pages</code><code class="php plain">);  </code> <div class="line number50 index49 alt1"> <code class="php spaces">    </code><code class="php plain">unset(</code><code class="php variable">$pageNums</code><code class="php plain">);  </code> <div class="line number51 index50 alt2"> <code class="php spaces">    </code><code class="php plain">unset(</code><code class="php variable">$page_array</code><code class="php plain">);  </code> <div class="line number52 index51 alt1"> <code class="php spaces">    </code><code class="php plain">unset(</code><code class="php variable">$subPage_link</code><code class="php plain">);  </code> <div class="line number53 index52 alt2"> <code class="php spaces">    </code><code class="php plain">unset(</code><code class="php variable">$subPage_type</code><code class="php plain">);  </code> <div class="line number54 index53 alt1"> <code class="php spaces">   </code><code class="php plain">}  </code> <div class="line number55 index54 alt2"> <code class="php spaces">    </code> <div class="line number56 index55 alt1"> <code class="php spaces">  </code><code class="php comments">/* </code> <div class="line number57 index56 alt2"> <code class="php spaces">    </code><code class="php comments">show_SubPages函数用在构造函数里面。而且用来判断显示什么样子的分页   </code> <div class="line number58 index57 alt1"> <code class="php spaces">   </code><code class="php comments">*/</code> <div class="line number59 index58 alt2"> <code class="php spaces">  </code><code class="php keyword">function</code> <code class="php plain">show_SubPages(</code><code class="php variable">$subPage_type</code><code class="php plain">){  </code> <div class="line number60 index59 alt1"> <code class="php spaces">    </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$subPage_type</code> <code class="php plain">== 1){  </code> <div class="line number61 index60 alt2"> <code class="php spaces">    </code><code class="php variable">$this</code><code class="php plain">->subPageCss1();  </code> <div class="line number62 index61 alt1"> <code class="php spaces">    </code><code class="php plain">}</code><code class="php keyword">elseif</code> <code class="php plain">(</code><code class="php variable">$subPage_type</code> <code class="php plain"> == 2){  </code> <div class="line number63 index62 alt2"> <code class="php spaces">    </code><code class="php variable">$this</code><code class="php plain">->subPageCss2();  </code> <div class="line number64 index63 alt1"> <code class="php spaces">    </code><code class="php plain">}  </code> <div class="line number65 index64 alt2"> <code class="php spaces">   </code><code class="php plain">}  </code> <div class="line number66 index65 alt1"> <code class="php spaces">    </code> <div class="line number67 index66 alt2"> <code class="php spaces">    </code> <div class="line number68 index67 alt1"> <code class="php spaces">  </code><code class="php comments">/* </code><div class="line number69 index68 alt2"> <code class="php spaces">    </code><code class="php comments">用来给建立分页的数组初始化的函数。 </code> <div class="line number70 index69 alt1"> <code class="php spaces">   </code><code class="php comments">*/</code> <div class="line number71 index70 alt2"> <code class="php spaces">  </code><code class="php keyword">function</code> <code class="php plain">initArray(){  </code> <div class="line number72 index71 alt1"> <code class="php spaces">    </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code><code class="php plain">=0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php variable">$this</code><code class="php plain">->sub_pages;</code><code class="php variable">$i</code><code class="php plain">++){  </code> <div class="line number73 index72 alt2"> <code class="php spaces">    </code><code class="php variable">$this</code><code class="php plain">->page_array[</code><code class="php variable">$i</code><code class="php plain">]=</code><code class="php variable">$i</code><code class="php plain">;  </code> <div class="line number74 index73 alt1"> <code class="php spaces">    </code><code class="php plain">}  </code> <div class="line number75 index74 alt2"> <code class="php spaces">    </code><code class="php keyword">return</code> <code class="php variable">$this</code><code class="php plain">->page_array;  </code> <div class="line number76 index75 alt1"> <code class="php spaces">   </code><code class="php plain">}  </code> <div class="line number77 index76 alt2"> <code class="php spaces">    </code> <div class="line number78 index77 alt1"> <code class="php spaces">    </code> <div class="line number79 index78 alt2"> <code class="php spaces">  </code><code class="php comments">/* </code> <div class="line number80 index79 alt1"> <code class="php spaces">    </code><code class="php comments">construct_num_Page该函数使用来构造显示的条目 </code> <div class="line number81 index80 alt2"> <code class="php spaces">    </code><code class="php comments">即使:[1][2][3][4][5][6][7][8][9][10] </code> <div class="line number82 index81 alt1"> <code class="php spaces">   </code><code class="php comments">*/</code> <div class="line number83 index82 alt2"> <code class="php spaces">  </code><code class="php keyword">function</code> <code class="php plain">construct_num_Page(){  </code> <div class="line number84 index83 alt1"> <code class="php spaces">    </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->pageNums < </code><code class="php variable">$this</code><code class="php plain">->sub_pages){  </code> <div class="line number85 index84 alt2"> <code class="php spaces">    </code><code class="php variable">$current_array</code><code class="php plain">=</code><code class="php keyword">array</code><code class="php plain">();  </code> <div class="line number86 index85 alt1"> <code class="php spaces">     </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code><code class="php plain">=0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php variable">$this</code><code class="php plain">->pageNums;</code><code class="php variable">$i</code><code class="php plain">++){   </code> <div class="line number87 index86 alt2"> <code class="php spaces">     </code><code class="php variable">$current_array</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">]=</code><code class="php variable">$i</code><code class="php plain">+1;  </code> <div class="line number88 index87 alt1"> <code class="php spaces">     </code><code class="php plain">}  </code> <div class="line number89 index88 alt2"> <code class="php spaces">    </code><code class="php plain">}</code><code class="php keyword">else</code><code class="php plain">{  </code> <div class="line number90 index89 alt1"> <code class="php spaces">    </code><code class="php variable">$current_array</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->initArray();  </code><div class="line number91 index90 alt2"> <code class="php spaces">     </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->current_page <= 3){ </code></p> <div class="line number92 index91 alt1"><code class="php spaces"> </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code><code class="php plain">=0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php functions">count</code><code class="php plain">(</code><code class="php variable">$current_array</code><code class="php plain">);</code><code class="php variable">$i</code><code class="php plain">&#43;&#43;){ </code></p> <div class="line number93 index92 alt2"><code class="php spaces"> </code><code class="php variable">$current_array</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">]=</code><code class="php variable">$i</code><code class="php plain">&#43;1; </code></p> <div class="line number94 index93 alt1"><code class="php spaces"> </code><code class="php plain">} </code></p> <div class="line number95 index94 alt2"><code class="php spaces"> </code><code class="php plain">}</code><code class="php keyword">elseif</code> <code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->current_page <= </code><code class="php variable">$this</code><code class="php plain">->pageNums && </code><code class="php variable">$this</code><code class="php plain">->current_page > </code><code class="php variable">$this</code><code class="php plain">->pageNums - </code><code class="php variable">$this</code><code class="php plain">->sub_pages + 1 ){  </code> <div class="line number96 index95 alt1"> <code class="php spaces">      </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code><code class="php plain">=0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php functions">count</code><code class="php plain">(</code><code class="php variable">$current_array</code><code class="php plain">);</code><code class="php variable">$i</code><code class="php plain">&#43;&#43;){ </code></p> <div class="line number97 index96 alt2"><code class="php spaces"> </code><code class="php variable">$current_array</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">]=(</code><code class="php variable">$this</code><code class="php plain">->pageNums)-(</code><code class="php variable">$this</code><code class="php plain">->sub_pages)+1+</code><code class="php variable">$i</code><code class="php plain">;  </code> <div class="line number98 index97 alt1"> <code class="php spaces">      </code><code class="php plain">}  </code> <div class="line number99 index98 alt2"> <code class="php spaces">     </code><code class="php plain">}</code><code class="php keyword">else</code><code class="php plain">{  </code> <div class="line number100 index99 alt1"> <code class="php spaces">      </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code><code class="php plain">=0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php functions">count</code><code class="php plain">(</code><code class="php variable">$current_array</code><code class="php plain">);</code><code class="php variable">$i</code><code class="php plain">&#43;&#43;){ </code></p> <div class="line number101 index100 alt2"><code class="php spaces"> </code><code class="php variable">$current_array</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">]=</code><code class="php variable">$this</code><code class="php plain">->current_page-2+</code><code class="php variable">$i</code><code class="php plain">;  </code> <div class="line number102 index101 alt1"> <code class="php spaces">      </code><code class="php plain">}  </code> <div class="line number103 index102 alt2"> <code class="php spaces">     </code><code class="php plain">}  </code> <div class="line number104 index103 alt1"> <code class="php spaces">    </code><code class="php plain">}  </code><div class="line number105 index104 alt2"> <code class="php spaces">     </code> <div class="line number106 index105 alt1"> <code class="php spaces">    </code><code class="php keyword">return</code> <code class="php variable">$current_array</code><code class="php plain">;  </code> <div class="line number107 index106 alt2"> <code class="php spaces">   </code><code class="php plain">}  </code> <div class="line number108 index107 alt1"> <code class="php spaces">    </code> <div class="line number109 index108 alt2"> <code class="php spaces">  </code><code class="php comments">/* </code> <div class="line number110 index109 alt1"> <code class="php spaces">   </code><code class="php comments">构造普通模式的分页 </code> <div class="line number111 index110 alt2"> <code class="php spaces">   </code><code class="php comments">共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页] </code> <div class="line number112 index111 alt1"> <code class="php spaces">   </code><code class="php comments">*/</code> <div class="line number113 index112 alt2"> <code class="php spaces">  </code><code class="php keyword">function</code> <code class="php plain">subPageCss1(){  </code> <div class="line number114 index113 alt1"> <code class="php spaces">   </code><code class="php variable">$subPageCss1Str</code><code class="php plain">=</code><code class="php string">""</code><code class="php plain">;  </code> <div class="line number115 index114 alt2"> <code class="php spaces">   </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"共"</code><code class="php plain">.</code><code class="php variable">$this</code><code class="php plain">->nums.</code><code class="php string">"条记录,"</code><code class="php plain">;  </code> <div class="line number116 index115 alt1"> <code class="php spaces">   </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"每页显示"</code><code class="php plain">.</code><code class="php variable">$this</code><code class="php plain">->each_disNums.</code><code class="php string">"条,"</code><code class="php plain">;  </code> <div class="line number117 index116 alt2"> <code class="php spaces">   </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"当前第"</code><code class="php plain">.</code><code class="php variable">$this</code><code class="php plain">->current_page.</code><code class="php string">"/"</code><code class="php plain">.</code><code class="php variable">$this</code><code class="php plain">->pageNums.</code><code class="php string">"页 "</code><code class="php plain">;  </code> <div class="line number118 index117 alt1"> <code class="php spaces">    </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->current_page > 1){  </code> <div class="line number119 index118 alt2"> <code class="php spaces">    </code><code class="php variable">$firstPageUrl</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.</code><code class="php string">"1"</code><code class="php plain">;  </code> <div class="line number120 index119 alt1"> <code class="php spaces">    </code><code class="php variable">$prewPageUrl</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.(</code><code class="php variable">$this</code><code class="php plain">->current_page-1);  </code> <div class="line number121 index120 alt2"> <code class="php spaces">    </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"[<a href='$firstPageUrl'>首页</a>] "</code><code class="php plain">;  </code> <div class="line number122 index121 alt1"> <code class="php spaces">    </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"[<a href='$prewPageUrl'>上一页</a>] "</code><code class="php plain">;  </code><div class="line number123 index122 alt2"> <code class="php spaces">    </code><code class="php plain">}</code><code class="php keyword">else</code> <code class="php plain">{  </code> <div class="line number124 index123 alt1"> <code class="php spaces">    </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"[首页] "</code><code class="php plain">;  </code> <div class="line number125 index124 alt2"> <code class="php spaces">    </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"[上一页] "</code><code class="php plain">;  </code> <div class="line number126 index125 alt1"> <code class="php spaces">    </code><code class="php plain">}  </code> <div class="line number127 index126 alt2"> <code class="php spaces">     </code> <div class="line number128 index127 alt1"> <code class="php spaces">    </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->current_page < </code><code class="php variable">$this</code><code class="php plain">->pageNums){  </code> <div class="line number129 index128 alt2"> <code class="php spaces">    </code><code class="php variable">$lastPageUrl</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.</code><code class="php variable">$this</code><code class="php plain">->pageNums;  </code> <div class="line number130 index129 alt1"> <code class="php spaces">    </code><code class="php variable">$nextPageUrl</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.(</code><code class="php variable">$this</code><code class="php plain">->current_page+1);  </code> <div class="line number131 index130 alt2"> <code class="php spaces">    </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">" [<a href='$nextPageUrl'>下一页</a>] "</code><code class="php plain">;  </code> <div class="line number132 index131 alt1"> <code class="php spaces">    </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"[<a href='$lastPageUrl'>尾页</a>] "</code><code class="php plain">;  </code> <div class="line number133 index132 alt2"> <code class="php spaces">    </code><code class="php plain">}</code><code class="php keyword">else</code> <code class="php plain">{  </code> <div class="line number134 index133 alt1"> <code class="php spaces">    </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"[下一页] "</code><code class="php plain">;  </code> <div class="line number135 index134 alt2"> <code class="php spaces">    </code><code class="php variable">$subPageCss1Str</code><code class="php plain">.=</code><code class="php string">"[尾页] "</code><code class="php plain">;  </code> <div class="line number136 index135 alt1"> <code class="php spaces">    </code><code class="php plain">}  </code> <div class="line number137 index136 alt2"> <code class="php spaces">     </code> <div class="line number138 index137 alt1"> <code class="php spaces">    </code><code class="php functions">echo</code> <code class="php variable">$subPageCss1Str</code><code class="php plain">;  </code> <div class="line number139 index138 alt2"> <code class="php spaces">     </code> <div class="line number140 index139 alt1"> <code class="php spaces">   </code><code class="php plain">}  </code> <div class="line number141 index140 alt2"> <code class="php spaces">    </code> <div class="line number142 index141 alt1"> <code class="php spaces">    </code> <div class="line number143 index142 alt2"> <code class="php spaces">  </code><code class="php comments">/* </code> <div class="line number144 index143 alt1"> <code class="php spaces">   </code><code class="php comments">构造经典模式的分页 </code><div class="line number145 index144 alt2"> <code class="php spaces">   </code><code class="php comments">当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页] </code> <div class="line number146 index145 alt1"> <code class="php spaces">   </code><code class="php comments">*/</code> <div class="line number147 index146 alt2"> <code class="php spaces">  </code><code class="php keyword">function</code> <code class="php plain">subPageCss2(){  </code> <div class="line number148 index147 alt1"> <code class="php spaces">   </code><code class="php variable">$subPageCss2Str</code><code class="php plain">=</code><code class="php string">""</code><code class="php plain">;  </code> <div class="line number149 index148 alt2"> <code class="php spaces">   </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"当前第"</code><code class="php plain">.</code><code class="php variable">$this</code><code class="php plain">->current_page.</code><code class="php string">"/"</code><code class="php plain">.</code><code class="php variable">$this</code><code class="php plain">->pageNums.</code><code class="php string">"页 "</code><code class="php plain">;  </code> <div class="line number150 index149 alt1"> <code class="php spaces">     </code> <div class="line number151 index150 alt2"> <code class="php spaces">     </code> <div class="line number152 index151 alt1"> <code class="php spaces">    </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->current_page > 1){  </code> <div class="line number153 index152 alt2"> <code class="php spaces">    </code><code class="php variable">$firstPageUrl</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.</code><code class="php string">"1"</code><code class="php plain">;  </code> <div class="line number154 index153 alt1"> <code class="php spaces">    </code><code class="php variable">$prewPageUrl</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.(</code><code class="php variable">$this</code><code class="php plain">->current_page-1);  </code> <div class="line number155 index154 alt2"> <code class="php spaces">    </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[<a href='$firstPageUrl'>首页</a>] "</code><code class="php plain">;  </code> <div class="line number156 index155 alt1"> <code class="php spaces">    </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[<a href='$prewPageUrl'>上一页</a>] "</code><code class="php plain">;  </code> <div class="line number157 index156 alt2"> <code class="php spaces">    </code><code class="php plain">}</code><code class="php keyword">else</code> <code class="php plain">{  </code> <div class="line number158 index157 alt1"> <code class="php spaces">    </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[首页] "</code><code class="php plain">;  </code> <div class="line number159 index158 alt2"> <code class="php spaces">    </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[上一页] "</code><code class="php plain">;  </code> <div class="line number160 index159 alt1"> <code class="php spaces">    </code><code class="php plain">}  </code> <div class="line number161 index160 alt2"> <code class="php spaces">     </code> <div class="line number162 index161 alt1"> <code class="php spaces">   </code><code class="php variable">$a</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->construct_num_Page();  </code><div class="line number163 index162 alt2"> <code class="php spaces">    </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code><code class="php plain">=0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php functions">count</code><code class="php plain">(</code><code class="php variable">$a</code><code class="php plain">);</code><code class="php variable">$i</code><code class="php plain">&#43;&#43;){ </code></p> <div class="line number164 index163 alt1"><code class="php spaces"> </code><code class="php variable">$s</code><code class="php plain">=</code><code class="php variable">$a</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">]; </code></p> <div class="line number165 index164 alt2"><code class="php spaces"> </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$s</code> <code class="php plain">== </code><code class="php variable">$this</code><code class="php plain">->current_page ){  </code> <div class="line number166 index165 alt1"> <code class="php spaces">     </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[<span style='color:red;font-weight:bold;'>"</code><code class="php plain">.</code><code class="php variable">$s</code><code class="php plain">.</code><code class="php string">"</span>]"</code><code class="php plain">;  </code> <div class="line number167 index166 alt2"> <code class="php spaces">     </code><code class="php plain">}</code><code class="php keyword">else</code><code class="php plain">{  </code> <div class="line number168 index167 alt1"> <code class="php spaces">     </code><code class="php variable">$url</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.</code><code class="php variable">$s</code><code class="php plain">;  </code> <div class="line number169 index168 alt2"> <code class="php spaces">     </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[<a href='$url'>"</code><code class="php plain">.</code><code class="php variable">$s</code><code class="php plain">.</code><code class="php string">"</a>]"</code><code class="php plain">;  </code> <div class="line number170 index169 alt1"> <code class="php spaces">     </code><code class="php plain">}  </code> <div class="line number171 index170 alt2"> <code class="php spaces">    </code><code class="php plain">}  </code> <div class="line number172 index171 alt1"> <code class="php spaces">     </code> <div class="line number173 index172 alt2"> <code class="php spaces">    </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->current_page < </code><code class="php variable">$this</code><code class="php plain">->pageNums){  </code> <div class="line number174 index173 alt1"> <code class="php spaces">    </code><code class="php variable">$lastPageUrl</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.</code><code class="php variable">$this</code><code class="php plain">->pageNums;  </code> <div class="line number175 index174 alt2"> <code class="php spaces">    </code><code class="php variable">$nextPageUrl</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->subPage_link.(</code><code class="php variable">$this</code><code class="php plain">->current_page+1);  </code> <div class="line number176 index175 alt1"> <code class="php spaces">    </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">" [<a href='$nextPageUrl'>下一页</a>] "</code><code class="php plain">;  </code> <div class="line number177 index176 alt2"> <code class="php spaces">    </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[<a href='$lastPageUrl'>尾页</a>] "</code><code class="php plain">;  </code><div class="line number178 index177 alt1"> <code class="php spaces">    </code><code class="php plain">}</code><code class="php keyword">else</code> <code class="php plain">{  </code> <div class="line number179 index178 alt2"> <code class="php spaces">    </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[下一页] "</code><code class="php plain">;  </code> <div class="line number180 index179 alt1"> <code class="php spaces">    </code><code class="php variable">$subPageCss2Str</code><code class="php plain">.=</code><code class="php string">"[尾页] "</code><code class="php plain">;  </code> <div class="line number181 index180 alt2"> <code class="php spaces">    </code><code class="php plain">}  </code> <div class="line number182 index181 alt1"> <code class="php spaces">    </code><code class="php functions">echo</code> <code class="php variable">$subPageCss2Str</code><code class="php plain">;  </code> <div class="line number183 index182 alt2"> <code class="php spaces">   </code><code class="php plain">}  </code> <div class="line number184 index183 alt1"> <code class="php plain">}  </code> <div class="line number185 index184 alt2"> <code class="php plain">?></code> <p><br> </p> <p></p> <h3>デモコード:</h3> <p></p> <p></p> <div class="container"> <div class="line number1 index0 alt2"> <code class="php plain"><?php </code></p> <div class="line number2 index1 alt1"><code class="php keyword">require_once</code><code class="php plain">(</code><code class="php string">"SubPages.php"</code><code class="php plain">); </code></p> <div class="line number3 index2 alt2"><code class="php comments">//每页显示的条数 </code> </p> <div class="line number4 index3 alt1"><code class="php spaces"> </code><code class="php variable">$page_size</code><code class="php plain">=20; </code></p> <div class="line number5 index4 alt2"><code class="php comments">//总条目数 </code></p> <div class="line number6 index5 alt1"><code class="php spaces"> </code><code class="php variable">$nums</code><code class="php plain">=1024; </code></p> <div class="line number7 index6 alt2"><code class="php comments">//每次显示的页数 </code> </p> <div class="line number8 index7 alt1"><code class="php spaces"> </code><code class="php variable">$sub_pages</code><code class="php plain">=10; </code></p> <div class="line number9 index8 alt2"><code class="php comments">//得到当前是第几页 </code> </p> <div class="line number10 index9 alt1"><code class="php spaces"> </code><code class="php variable">$pageCurrent</code><code class="php plain">=</code><code class="php variable">$_GET</code><code class="php plain">[</code><code class="php string">"p"</code><code class="php plain">]; </code></p> <div class="line number11 index10 alt2"><code class="php spaces"> </code><code class="php comments">//if(!$pageCurrent) $pageCurrent=1; </code></p> <div class="line number12 index11 alt1"><code class="php spaces"> </code> </p> <div class="line number13 index12 alt2"><code class="php spaces"> </code><code class="php variable">$subPages</code><code class="php plain">=</code><code class="php keyword">new</code> <code class="php plain">SubPages(</code><code class="php variable">$page_size</code><code class="php plain">,</code><code class="php variable">$nums</code><code class="php plain">,</code><code class="php variable">$pageCurrent</code><code class="php plain">,</code><code class="php variable">$sub_pages</code><code class="php plain">,</code><code class="php string">"test.php?p="</code><code class="php plain">,2); </code></p> <div class="line number14 index13 alt1"><code class="php plain">?></code> <br> <p></p> <div class="clear"></div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div></code></div> </div>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。