在贴一下代码吧
<?php $localh">简单的利用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 "
"; //上一页 、下一页 $pageprev = $page -1 ; if($page > $total){ $pagenext = $total; } else{ $pagenext = $page +1; } // 做链接 跳转; echo ""; while($row = mysql_fetch_assoc($result)){ $id = $row['id']; $name = $row['name']; echo " ID NAME "; } echo " ".$id." ".$name." 上一页 丨下一页
"; mysql_free_result($result); mysql_close($conn);?>关键点: 1、$sql = "select * from page order by id limit {$offset},{$pagesize}";
这两点是关键能体现 分页技术 和php 代码艺术的地方~
和大家一起学习吧~
Déclaration de ce site WebLe 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.cnDerniers articles par auteur
2024-10-22 09:46:29 2024-10-13 13:53:41 2024-10-12 12:15:51 2024-10-11 22:47:31 2024-10-11 19:36:51 2024-10-11 15:50:41 2024-10-11 15:07:41 2024-10-11 14:21:21 2024-10-11 12:59:11 2024-10-11 12:17:31Derniers numérosConversion automatique PX en erreur REM <style>html { taille de police : calc(100vw / 3,75); }body { taille de la...Depuis 2024-04-16 09:34:16004687Rubriques connexesPlus>
- mysql modifier le nom de la table de données
- MySQL crée une procédure stockée
- La différence entre MongoDB et MySQL
- Comment vérifier si le mot de passe MySQL est oublié
- mysql créer une base de données
- niveau d'isolement des transactions par défaut de MySQL
- La différence entre sqlserver et mysql
- mysqlmot de passe oublié