Heim >Backend-Entwicklung >PHP-Tutorial >php分页代码实例_PHP教程
<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>