时间:2021-07-01 10:21:17 帮助过:46人阅读
注:例子中的MYSQL用户名和密码以及表名和字段名请以你的为准,请修改这些信息后再测试。
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>应用limit子句实现分页显示</title> <script> //全选/取消全选 function chek(){ var leng = this.form1.chk.length; if(leng==undefined){ leng=1; if(!form1.chk.checked) document.form1.chk.checked=true; else document.form1.chk.checked=false; }else{ for( var i = 0; i < leng; i++) { if(!form1.chk[i].checked) document.form1.chk[i].checked = true; else document.form1.chk[i].checked = false; } } return false; } </script> <?php $conn = mysqli_connect("localhost","root","pwd");//连接MYSQL mysqli_query("set names gb2312"); mysqli_select_db("db_softinfo"); //指定数据表 ?> </head> <body> <center> <table width="798" border="0" cellpadding="0" cellspacing="0"> <tr> <td> <table width="100%" height="38" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="193" align="center" valign="middle"> <b><?php echo date("Y-m-d")." ".date(l);?></b></td> <td width="101" align="center" valign="middle"><a href="index.php?action=show" class="a">浏览目录</a></td> <td width="102" align="center" valign="middle"><a href="#">添加内容</a></td> <td width="101" align="center" valign="middle"><a href="#">简单查询</a></td> <td width="101" align="center" valign="middle"><a href="#">高级查询</a></td> <td width="101" align="center" valign="middle"><a href="#">分组统计</a></td> <td width="99" align="center" valign="middle"><a href="#">退出系统</a></td> </tr> </table> </td> </tr> </table> <table width="799" height="300" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center" valign="middle"> <?php //浏览数据库内容 if (($action == null) or ($_GET[action] == "show")){ ?> <form name="form1" id="form1" method="post"> <table width="90%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="25" width="5%" class="top"> </td> <td width="5%" class="top">id</td> <td width="30%" class="top">名称</td> <td width="10%" class="top">价格</td> <td width="20%" class="top">时间</td> <td width="10%" class="top">类别</td> <td width="10%" class="top">操作</td> </tr> <?php $pagesize = 5 ; //每页显示记录数 $sqlstr = "select * from tb_mrbook order by id"; $total = mysqli_query($sqlstr,$conn); $totalNum = mysqli_num_rows($total); //总记录数 $pagecount = (int)(($totalNum - 1) / $pagesize) + 1;//总页数 (!$absolutepage)?($absolutepage = 1):$absolutepage; //当前显示页数 ($absolutepage <= $pagecount)?$absolutepage:($absolutepage = $pagecount); $f_pageNum = $pagesize * ($absolutepage - 1);//当前页的第一条记录 $sqlstr1 = $sqlstr." limit ".$f_pageNum.",".$pagesize; $result = mysqli_query($sqlstr1,$conn); while ($rows = mysqli_fetch_row($result)){ echo "<tr><td height='25' align='center' class='m_td'>"; echo "<input type=checkbox name='chk[]' id='chk' value=".$rows[0].">"; echo "</td>"; for($i = 0; $i < count($rows); $i++){ echo "<td height='25' align='center' class='m_td'>".$rows[$i]."</td>"; } echo "<td class='m_td'><a href='#'>修改</a>/<a href='#'>删除</a></td>"; echo "</tr>"; } ?> <tr> <td height="25" colspan="7" class="m_td" align="left"><a href="" onClick="return chek();">全部选择/取消</a> <input type="hidden" name="action" value="delall"><input type="submit" value="删除选择" onclick = 'return false'> 共<?php echo $totalNum ?>本图书,第<?php echo $absolutepage ?>页/共<?php echo $pagecount ?>页:<a href="?absolutepage=<?php echo ($absolutepage > 1)?($absolutepage - 1):1;s?>">上一页</a> <a href="?absolutepage=<?php echo ($absolutepage < ($pagecount - 1))?($absolutepage+1):$pagecount;?>">下一页</a></td> </tr> </table> </form> <?php } ?> </td> </tr> </table> </center> </body> </html>
以上内容不足之处还请指出,不胜感激!
更多相关问题请访问PHP中文网:https://www.php.cn/
以上就是PHP基于limit子句的分页详细操作的详细内容,更多请关注Gxlcms其它相关文章!