>  기사  >  php教程  >  简单的php分页代码

简单的php分页代码

WBOY
WBOY원래의
2016-06-21 08:52:581155검색
<ol class="dp-c">
<li class="alt"><span><span><?php  </span></span></span></li>
<li><span> <span class="vars">$conn</span><span> = mysql_connect(</span><span class="string">'localhost'</span><span>,</span><span class="string">'root'</span><span>,</span><span class="string">'mysql'</span><span>); </span></span></li>
<li class="alt"><span> <span class="vars">$db</span><span> = mysql_select_db(</span><span class="string">"wiki"</span><span>); </span></span></li>
<li><span> <span class="vars">$q</span><span> = mysql_query(</span><span class="string">"select * from wiki_doc"</span><span>); </span></span></li>
<li class="alt"><span>  </span></li>
<li><span> <span class="vars">$num</span><span> = mysql_num_rows(</span><span class="vars">$q</span><span>); </span></span></li>
<li class="alt"><span> <span class="vars">$perpage</span><span> = 5; </span></span></li>
<li><span> <span class="vars">$totalpage</span><span> = @</span><span class="func">ceil</span><span>(</span><span class="vars">$num</span><span>/</span><span class="vars">$perpage</span><span>); </span></span></li>
<li class="alt"><span> <span class="vars">$page</span><span> =</span><span class="vars">$_GET</span><span>[</span><span class="string">'page'</span><span>]; </span></span></li>
<li><span>  </span></li>
<li class="alt"><span> <span class="keyword">if</span><span>(!isset(</span><span class="vars">$page</span><span>)){ </span></span></li>
<li><span>   <span class="vars">$page</span><span> = 1; </span></span></li>
<li class="alt"><span>    </span></li>
<li><span> } </span></li>
<li class="alt"><span>  </span></li>
<li><span> <span class="comment">//$start = ($page-1)*$perpage;</span><span> </span></span></li>
<li class="alt"><span> <span class="vars">$start</span><span> = (</span><span class="vars">$page</span><span>-1)*</span><span class="vars">$perpage</span><span>; </span></span></li>
<li><span> <span class="vars">$qq</span><span>=mysql_query(</span><span class="string">"select * from wiki_doc limit $start,$perpage"</span><span>); </span></span></li>
<li class="alt"><span> <span class="vars">$info</span><span> = </span><span class="keyword">array</span><span>(); </span></span></li>
<li><span> <span class="keyword">while</span><span>(</span><span class="vars">$result</span><span>=mysql_fetch_array(</span><span class="vars">$qq</span><span>)){ </span></span></li>
<li class="alt"><span>    <span class="vars">$info</span><span>[] = </span><span class="vars">$result</span><span>; </span></span></li>
<li><span> } </span></li>
<li class="alt"><span>  </span></li>
<li><span> <span class="func">echo</span><span> </span><span class="string">"<table>"<span>; </span><li class="alt"><span> <span class="keyword">foreach</span><span>(</span><span class="vars">$info</span><span> </span><span class="keyword">as</span><span> </span><span class="vars">$key</span><span>){ </span></span></li>
<li><span>   <span class="func">echo</span><span> </span><span class="string">"<tr>
<td>$key[did]</td>
<td> </td>
<td>$key[title]</td>
</tr>"</span><span>; </span></span></li>
<li class="alt"><span> } </span></li>
<li><span> <span class="func">echo</span><span> </span><span class="string">"</span></span></li>
</table>"</span><span>; </span></span></li>
<li class="alt"><span>  <span class="keyword">if</span><span>(</span><span class="vars">$page</span><span>!=1){?> </span></span></li>
<li>
<span>    <a class="string">"page2.php?page=<?php  echo $page-1; ?>"</a></span><span>>Prev </span>
</li>
<li class="alt"><span>    <?php  </span></span></li>
<li><span>  } </span></li>
<li class="alt"><span>  <span class="keyword">for</span><span>(</span><span class="vars">$i</span><span>=1;</span><span class="vars">$i</span><span><span class="vars">$totalpage</span><span>;</span><span class="vars">$i</span><span>++){ </span></span></span></li>
<li><span>    ?> </span></li>
<li class="alt">
<span>    <a class="string">"page2.php?page=<?php  echo $i; ?>"</a></span><span>><?php  </span><span class="func">echo</span><span> </span><span class="vars">$i</span><span>; ?> </span></span>
</li>
<li><span>    <?php  </span></span></li>
<li class="alt"><span>     </span></li>
<li><span>  } </span></li>
<li class="alt"><span>  <span class="keyword">if</span><span>(</span><span class="vars">$page</span><span><span class="vars">$totalpage</span><span>){?> </span></span></span></li>
<li>
<span>  <a class="string">"page2.php?page=<?php  echo $page+1; ?>"</a></span><span>>Next </span>
</li>
<li class="alt"><span>   <?php   </span></span></li>
<li><span>  }?>  </span></li>
</ol>



성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.