Heim >Backend-Entwicklung >PHP-Tutorial >php分页代码实例_PHP教程

php分页代码实例_PHP教程

WBOY
WBOYOriginal
2016-07-20 11:14:491303Durchsuche

<span $result</span> = "<div class=\"page-num\"><ul class=\"fn-clear\">"<span ;
    
    </span><span //</span><span  上一页</span>
    <span if</span> (<span $offset</span>>0<span ) {
        </span><span $result</span> .= "<span <li>
            <a href=\"</span>".<span $url</span>.'offset='.(<span $offset</span>-<span $maxrow</span>)."<span \">Prev</a>
        </li></span>"<span ;
    }
    
    </span><span $pages</span> = <span $allPageNums</span>;  <span //</span><span 总页数</span>
    <span $page</span> = <span $curPage</span>;    <span //</span><span 当前页数</span>
    <span $page_len</span> = 9<span ;
    </span><span $page_len</span> = (<span $page_len</span>%2)?<span $page_len</span>:<span $pagelen</span>+1;<span //</span><span 页码个数 </span>
    <span $pageoffset</span> = (<span $page_len</span>-1)/2;<span //</span><span 页码个数左右偏移量 </span>
    <span if</span>(<span $pages</span>><span $page_len</span><span ){ 
        </span><span //</span><span 如果当前页小于等于左偏移 </span>
        <span if</span>(<span $page</span><=<span $pageoffset</span><span ){ 
            </span><span $init</span>=1<span ; 
            </span><span $max_p</span> = <span $page_len</span><span ; 
        }</span><span else</span>{<span //</span><span 如果当前页大于左偏移 
            //如果当前页码右偏移超出最大分页数 </span>
            <span if</span>(<span $page</span>+<span $pageoffset</span>>=<span $pages</span>+1<span ){ 
                </span><span $init</span> = <span $pages</span>-<span $page_len</span>+1<span ;<br />         $max_p = $pages; 
            }</span><span else</span><span { 
                </span><span //</span><span 左右偏移都存在时的计算 </span>
                <span $init</span> = <span $page</span>-<span $pageoffset</span><span ; 
                </span><span $max_p</span> = <span $page</span>+<span $pageoffset</span><span ; 
            } 
        } 
    } else {<br />  <br />      $init = 1;<br />      $max_p = $pages;<br />  }

    </span><span for</span>(<span $i</span>=<span $init</span>; <span $i</span><=<span $max_p</span>; <span $i</span>++<span ) {
        
        </span><span if</span> ( <span $i</span> == <span $curPage</span><span  ) {
            </span><span $result</span> .=    "<li class=\"on\"><a href=\"".<span $url</span>.'offset='.(<span $i</span>*<span $maxrow</span>)."\" ><span $i</span></a></li>"<span ;
            </span><span continue</span><span ;
        }
        
        </span><span $result</span> .=    "<li><a href=\"".<span $url</span>.'offset='.((<span $i</span>-1)*<span $maxrow</span>)."\"><span $i</span></a></li>"<span ;
        
    }
    
    </span><span //</span><span  打印下一页</span>
    <span if</span> ( <span $allnums</span> > (<span $offset</span>+<span $maxrow</span><span ) ) {
        </span><span $result</span> .=    "<span <li>
            <a href=\"</span>".<span $url</span>.'offset='.(<span $offset</span>+<span $maxrow</span>)."<span \">Next</a>
        </li></span>"<span ;
    }</span>

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440264.htmlTechArticle= "div class=\"page-num\"ul class=\"fn-clear\"" ( 0 .= " ". .'offset='.( - )." " = ; = ; = 9 = ( %2)? : +1; = ( -1)/2; ( ( = =1 = { ( + = +1 = - +1 $max_p = $pages; } = - = + $init...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn