PHP セルフトレーニング プロジェクトの数値とテキストのページング効果は、関数
<span style="font-size: 16px;"><span style="color: #008000;"><br>/*</span><span style="color: #008000;">* * * @param $_sql * @param $_size </span><span style="color: #008000;">*/</span><span style="color: #0000ff;">function</span> _page(<span style="color: #800080;">$_sql</span>,<span style="color: #800080;">$_size</span><span style="color: #000000;">) { </span><span style="color: #008000;">//</span><span style="color: #008000;">将里面的所有变量取出来,外部可以访问</span> <span style="color: #0000ff;">global</span> <span style="color: #800080;">$_page</span>,<span style="color: #800080;">$_pagesize</span>,<span style="color: #800080;">$_pagenum</span>,<span style="color: #800080;">$_pageabsolute</span>,<span style="color: #800080;">$_num</span><span style="color: #000000;">; </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$_GET</span>['page'<span style="color: #000000;">])) { </span><span style="color: #800080;">$_page</span> = <span style="color: #800080;">$_GET</span>['page'<span style="color: #000000;">]; </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$_page</span>) || <span style="color: #800080;">$_page</span> < 0 || !<span style="color: #008080;">is_numeric</span>(<span style="color: #800080;">$_page</span><span style="color: #000000;">)) { </span><span style="color: #800080;">$_page</span> = 1<span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #800080;">$_page</span> = <span style="color: #008080;">intval</span>(<span style="color: #800080;">$_page</span><span style="color: #000000;">); } } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #800080;">$_page</span> = 1<span style="color: #000000;">; } </span><span style="color: #800080;">$_pagesize</span> = <span style="color: #800080;">$_size</span><span style="color: #000000;">; </span><span style="color: #800080;">$_num</span> = _num_rows(_query(<span style="color: #800080;">$_sql</span><span style="color: #000000;">)); </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$_num</span> == 0<span style="color: #000000;">) { </span><span style="color: #800080;">$_pageabsolute</span> = 1<span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #800080;">$_pageabsolute</span> = <span style="color: #008080;">ceil</span>(<span style="color: #800080;">$_num</span> / <span style="color: #800080;">$_pagesize</span><span style="color: #000000;">); } </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$_page</span> > <span style="color: #800080;">$_pageabsolute</span><span style="color: #000000;">) { </span><span style="color: #800080;">$_page</span> = <span style="color: #800080;">$_pageabsolute</span><span style="color: #000000;">; } </span><span style="color: #800080;">$_pagenum</span> = (<span style="color: #800080;">$_page</span> - 1) * <span style="color: #800080;">$_pagesize</span><span style="color: #000000;">;}</span><span style="color: #008000;">/*</span><span style="color: #008000;">* * _paging分页函数 * @param $_type * @return 返回分页 </span><span style="color: #008000;">*/</span><span style="color: #0000ff;">function</span> _paging(<span style="color: #800080;">$_type</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">global</span> <span style="color: #800080;">$_page</span>,<span style="color: #800080;">$_pageabsolute</span>,<span style="color: #800080;">$_num</span><span style="color: #000000;">; </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$_type</span> == 1<span style="color: #000000;">) { </span><span style="color: #0000ff;">echo</span> '<div id="page_num">'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '<ul>'<span style="color: #000000;">; </span><span style="color: #0000ff;">for</span> (<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span><<span style="color: #800080;">$_pageabsolute</span>;<span style="color: #800080;">$i</span>++<span style="color: #000000;">) { </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$_page</span> == (<span style="color: #800080;">$i</span>+1<span style="color: #000000;">)) { </span><span style="color: #0000ff;">echo</span> '<li><a href="blog.php?page='.(<span style="color: #800080;">$i</span>+1).'" class="selected">'.(<span style="color: #800080;">$i</span>+1).'</a></li>'<span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">echo</span> '<li><a href="blog.php?page='.(<span style="color: #800080;">$i</span>+1).'">'.(<span style="color: #800080;">$i</span>+1).'</a></li>'<span style="color: #000000;">; } } </span><span style="color: #0000ff;">echo</span> '</ul>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '</div>'<span style="color: #000000;">; } </span><span style="color: #0000ff;">elseif</span> (<span style="color: #800080;">$_type</span> == 2<span style="color: #000000;">) { </span><span style="color: #0000ff;">echo</span> '<div id="page_text">'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '<ul>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '<li>'.<span style="color: #800080;">$_page</span>.'/'.<span style="color: #800080;">$_pageabsolute</span>.'页 | </li>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '<li>共有<strong>'.<span style="color: #800080;">$_num</span>.'</strong>个会员 | </li>'<span style="color: #000000;">; </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$_page</span> == 1<span style="color: #000000;">) { </span><span style="color: #0000ff;">echo</span> '<li>首页 | </li>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '<li>上一页 | </li>'<span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">echo</span> '<li><a href="'.SCRIPT.'.php">首页</a> | </li>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '<li><a href="'.SCRIPT.'.php?page='.(<span style="color: #800080;">$_page</span>-1).'">上一页</a> | </li>'<span style="color: #000000;">; } </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$_page</span> == <span style="color: #800080;">$_pageabsolute</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">echo</span> '<li>下一页 | </li>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '<li>尾页</li>'<span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">echo</span> '<li><a href="'.SCRIPT.'.php?page='.(<span style="color: #800080;">$_page</span>+1).'">下一页</a> | </li>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '<li><a href="'.SCRIPT.'.php?page='.<span style="color: #800080;">$_pageabsolute</span>.'">尾页</a></li>'<span style="color: #000000;">; } </span><span style="color: #0000ff;">echo</span> '</ul>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> '</div>'<span style="color: #000000;">; }}</span></span>
で実装されています。上記のコードをコア関数ライブラリ glob.funic.php
そして、ファイル内で次の関数を呼び出すだけです:
//_pageing 関数はページングを呼び出します、1|2 、1 はデジタル ページングを意味し、2 はテキスト ページングを意味します Paging
_paging(2);
?>