ホームページ  >  記事  >  php教程  >  単純なPHPページネーションコード

単純なPHPページネーションコード

WBOY
WBOYオリジナル
2016-06-21 08:52:581159ブラウズ
<ol class="dp-c">
<li class="alt"><span><span><?php </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>; </span></span></li>
<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">"</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 href=<span class="string">"page2.php?page=<?php echo $page-1; ?>"</span><span>>Prev</a> </span>
</li>
<li class="alt"><span>    <?php </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><span class="vars">$totalpage</span><span>;</span><span class="vars">$i</span><span>++){ </span></span></li><li><span>    ?> </span></li>
<li class="alt">
<span>    <a href=<span class="string">"page2.php?page=<?php echo $i; ?>"</span><span>><?php </span><span class="func">echo</span><span> </span><span class="vars">$i</span><span>; ?></a> </span>
</li>
<li><span>    <?php </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><span class="vars">$totalpage</span><span>){?> </span></li>
<li>
<span>  <a href=<span class="string">"page2.php?page=<?php echo $page+1; ?>"</span><span>>Next</a> </span>
</li>
<li class="alt"><span>   <?php  </span></li><li><span>  }?>  </span></li>
</ol>



声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。