在贴一下代码吧

<?php        $localh">


    



















    
    
    
    
    
    
    
        




























    
    
    
    
    




Maison > développement back-end > tutoriel php > 容易的利用php谢了一个分页的功能模块

容易的利用php谢了一个分页的功能模块

WBOY
Libérer: 2016-06-13 12:21:48
original
874 Les gens l'ont consulté

简单的利用php谢了一个分页的功能模块

先贴张图看看效果

 

 

 

在贴一下代码吧

<span style="color: #000000;">php        </span><span style="color: #800080;">$localhost</span> = "localhost"<span style="color: #000000;">;    </span><span style="color: #800080;">$username</span> = "root"<span style="color: #000000;">;    </span><span style="color: #800080;">$password</span> = "root"<span style="color: #000000;">;    </span><span style="color: #800080;">$db</span> = "test";         <span style="color: #008000;">//</span><span style="color: #008000;">信息</span>        <span style="color: #800080;">$pagesize</span> = 5<span style="color: #000000;">;                                  </span><span style="color: #800080;">$conn</span> = <span style="color: #008080;">mysql_connect</span>(<span style="color: #800080;">$localhost</span>,<span style="color: #800080;">$username</span>,<span style="color: #800080;">$password</span>); <span style="color: #008000;">//</span><span style="color: #008000;">链接数据库</span>            <span style="color: #0000ff;">if</span>(!<span style="color: #800080;">$conn</span><span style="color: #000000;">){            </span><span style="color: #0000ff;">echo</span> "数据库链接失败".<span style="color: #008080;">mysql_error</span><span style="color: #000000;">();        }        </span><span style="color: #008080;">mysql_query</span>("SET NAMES 'UTF8'");    <span style="color: #008000;">//</span><span style="color: #008000;">编码转化</span>    <span style="color: #800080;">$db_select</span> = <span style="color: #008080;">mysql_select_db</span>(<span style="color: #800080;">$db</span>);  <span style="color: #008000;">//</span><span style="color: #008000;">选择表                                        //查询记录总数</span>    <span style="color: #800080;">$total_sql</span> = "select COUNT(*) from page"<span style="color: #000000;">;    </span><span style="color: #800080;">$total_result</span> = <span style="color: #008080;">mysql_query</span>(<span style="color: #800080;">$total_sql</span><span style="color: #000000;">);    </span><span style="color: #800080;">$total_row_arr</span> = <span style="color: #008080;">mysql_fetch_row</span>(<span style="color: #800080;">$total_result</span><span style="color: #000000;">);    </span><span style="color: #800080;">$total_row</span> = <span style="color: #800080;">$total_row_arr</span>[0];         <span style="color: #008000;">//</span><span style="color: #008000;">总条数    //总页数</span>    <span style="color: #800080;">$total</span> = <span style="color: #008080;">ceil</span>(<span style="color: #800080;">$total_row</span> / <span style="color: #800080;">$pagesize</span><span style="color: #000000;">);        </span><span style="color: #008000;">//</span><span style="color: #008000;">当前页数</span>    <span style="color: #800080;">$page</span> = @<span style="color: #800080;">$_GET</span>['p'] ? <span style="color: #800080;">$_GET</span>['p'] : 1<span style="color: #000000;">;         </span><span style="color: #008000;">//</span><span style="color: #008000;">limit 下限</span>    <span style="color: #800080;">$offset</span> = (<span style="color: #800080;">$page</span> - 1)*<span style="color: #800080;">$pagesize</span><span style="color: #000000;">;            </span><span style="color: #800080;">$sql</span> = "select * from page order by id limit {<span style="color: #800080;">$offset</span>},{<span style="color: #800080;">$pagesize</span>}"<span style="color: #000000;">;        </span><span style="color: #800080;">$result</span> = <span style="color: #008080;">mysql_query</span>(<span style="color: #800080;">$sql</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">echo</span> "<p>PHP分页代码的小模块</p>"<span style="color: #000000;">;    </span><span style="color: #0000ff;">echo</span> "
Copier après la connexion
"; echo ""; while($row = mysql_fetch_assoc($result)){ $id = $row['id']; $name = $row['name']; echo ""; } echo "
ID NAME
".$id." ".$name."
"; //上一页 、下一页 $pageprev = $page -1 ; if($page > $total){ $pagenext = $total; } else{ $pagenext = $page +1; } // 做链接 跳转; echo "

上一页下一页

"; mysql_free_result($result); mysql_close($conn);?>

关键点: 1、$sql = "select * from page order by id limit {$offset},{$pagesize}";

     2、echo "

上一页下一页

";

这两点是关键能体现 分页技术 和php 代码艺术的地方~

和大家一起学习吧~

É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
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal