Maison > php教程 > php手册 > le corps du texte

简单的php分页代码

WBOY
Libérer: 2016-06-21 08:52:58
original
1159 Les gens l'ont consulté
<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>
Copier après la connexion



Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal