PHP自练项目之数字与文字的分页效果在函数中实现,_PHP教程

WBOY
풀어 주다: 2016-07-13 09:45:57
원래의
990명이 탐색했습니다.

PHP自练项目之数字与文字的分页效果在函数中实现,

<span><span><br />/*</span><span>*
 * 
 * @param $_sql
 * @param $_size
 </span><span>*/</span>

<span>function</span> _page(<span>$_sql</span>,<span>$_size</span><span>) {
    </span><span>//</span><span>将里面的所有变量取出来,外部可以访问</span>
    <span>global</span> <span>$_page</span>,<span>$_pagesize</span>,<span>$_pagenum</span>,<span>$_pageabsolute</span>,<span>$_num</span><span>;
    </span><span>if</span> (<span>isset</span>(<span>$_GET</span>['page'<span>])) {
        </span><span>$_page</span> = <span>$_GET</span>['page'<span>];
        </span><span>if</span> (<span>empty</span>(<span>$_page</span>) || <span>$_page</span> < 0 || !<span>is_numeric</span>(<span>$_page</span><span>)) {
            </span><span>$_page</span> = 1<span>;
        } </span><span>else</span><span> {
            </span><span>$_page</span> = <span>intval</span>(<span>$_page</span><span>);
        }
    } </span><span>else</span><span> {
        </span><span>$_page</span> = 1<span>;
    }
    </span><span>$_pagesize</span> = <span>$_size</span><span>;
    </span><span>$_num</span> = _num_rows(_query(<span>$_sql</span><span>));
    </span><span>if</span> (<span>$_num</span> == 0<span>) {
        </span><span>$_pageabsolute</span> = 1<span>;
    } </span><span>else</span><span> {
        </span><span>$_pageabsolute</span> = <span>ceil</span>(<span>$_num</span> / <span>$_pagesize</span><span>);
    }
    </span><span>if</span> (<span>$_page</span> > <span>$_pageabsolute</span><span>) {
        </span><span>$_page</span> = <span>$_pageabsolute</span><span>;
    }
    </span><span>$_pagenum</span> = (<span>$_page</span> - 1) * <span>$_pagesize</span><span>;
}


</span><span>/*</span><span>*
 * _paging分页函数
 * @param $_type
 * @return 返回分页
 </span><span>*/</span>

<span>function</span> _paging(<span>$_type</span><span>) {
    </span><span>global</span> <span>$_page</span>,<span>$_pageabsolute</span>,<span>$_num</span><span>;
    </span><span>if</span> (<span>$_type</span> == 1<span>) {
        </span><span>echo</span> '<div id="page_num">'<span>;
        </span><span>echo</span> '<ul>'<span>;
                </span><span>for</span> (<span>$i</span>=0;<span>$i</span><<span>$_pageabsolute</span>;<span>$i</span>++<span>) {
                        </span><span>if</span> (<span>$_page</span> == (<span>$i</span>+1<span>)) {
                            </span><span>echo</span> '<li><a href="blog.php?page='.(<span>$i</span>+1).'" class="selected">'.(<span>$i</span>+1).'</a></li>'<span>;
                        } </span><span>else</span><span> {
                            </span><span>echo</span> '<li><a href="blog.php?page='.(<span>$i</span>+1).'">'.(<span>$i</span>+1).'</a></li>'<span>;
                        }
                }
        </span><span>echo</span> '</ul>'<span>;
        </span><span>echo</span> '</div>'<span>;
    } </span><span>elseif</span> (<span>$_type</span> == 2<span>) {
        </span><span>echo</span> '<div id="page_text">'<span>;
        </span><span>echo</span> '<ul>'<span>;
        </span><span>echo</span> '<li>'.<span>$_page</span>.'/'.<span>$_pageabsolute</span>.'页 | </li>'<span>;
        </span><span>echo</span> '<li>共有<strong>'.<span>$_num</span>.'</strong>个会员 | </li>'<span>;
                </span><span>if</span> (<span>$_page</span> == 1<span>) {
                    </span><span>echo</span> '<li>首页 | </li>'<span>;
                    </span><span>echo</span> '<li>上一页 | </li>'<span>;
                } </span><span>else</span><span> {
                    </span><span>echo</span> '<li><a href="'.SCRIPT.'.php">首页</a> | </li>'<span>;
                    </span><span>echo</span> '<li><a href="'.SCRIPT.'.php?page='.(<span>$_page</span>-1).'">上一页</a> | </li>'<span>;
                }
                </span><span>if</span> (<span>$_page</span> == <span>$_pageabsolute</span><span>) {
                    </span><span>echo</span> '<li>下一页 | </li>'<span>;
                    </span><span>echo</span> '<li>尾页</li>'<span>;
                } </span><span>else</span><span> {
                    </span><span>echo</span> '<li><a href="'.SCRIPT.'.php?page='.(<span>$_page</span>+1).'">下一页</a> | </li>'<span>;
                    </span><span>echo</span> '<li><a href="'.SCRIPT.'.php?page='.<span>$_pageabsolute</span>.'">尾页</a></li>'<span>;
                }
        </span><span>echo</span> '</ul>'<span>;
        </span><span>echo</span> '</div>'<span>;
    }
}</span></span>
로그인 후 복사

在核心函数库包装以上代码glob.funic.php

然后只要在文件中调用以下函数就行:


//_pageing函数调用分页,1|2,1表示数字分页,2表示文本分页
_paging(2);
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1038571.htmlTechArticlePHP自练项目之数字与文字的分页效果在函数中实现, /* * * * @param $_sql * @param $_size */ function _page( $_sql , $_size ) { // 将里面的所有变量取出来...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿