PHP+MySQL实现输入页码跳转到指定页面功能示例

<?php $id=mysql_connect("localhost","root","root")or dir('连接失败' . mysql_error()); if(mysql_select_db("db_database13",$id)) echo ""; else echo ('连接失败' . mysql_error()); mysql_query("set names gb2312"); ?>

index.php:

<?php session_start();include("conn/conn.php"); if ($_GET['page']=="") {$_GET['page']=1;};?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>查询结果的分页显示</title> <style type="text/css"> <!-- .STYLE1 {font-size: 12px} .STYLE2 {font-size: 13px} a:link { text-decoration: none; } a:visited { text-decoration: none; } a:hover { text-decoration: none; } a:active { text-decoration: none; } --> </style> </head> <script language="javascript"> function chk(form){ if(form.page.value<=0||form.page.value>form.pages.value){ alert("您输入的页码无效!!"); form.page.focus(); return(false); } return(true); } </script> <body> <table cellpadding="0" cellspacing="1" bgcolor="#11DFF0"> <tr> <td bgcolor="#11DFF0">姓名</td> <td bgcolor="#11DFF0">编号</td> <td bgcolor="#11DFF0">电话</td> <td bgcolor="#11DFF0">地址</td> </tr> <?php if($_GET['page']){ $page_size=3; $query="select count(*) as total from tb_insert"; $result=mysql_query($query); $message_count=mysql_result($result,0,"total"); $page_count=ceil($message_count/$page_size); $offset=($_GET['page']-1)*$page_size; $query="select * from tb_insert where id order by id desc limit $offset, $page_size"; $result=mysql_query($query); while ($myrow=@mysql_fetch_array($result)){ ?> <tr> <td bgcolor="#FFFFFF"><span><?php echo $myrow[name];?></span></td> <td bgcolor="#FFFFFF"><span><?php echo $myrow[number];?></span></td> <td bgcolor="#FFFFFF"><span><?php echo $myrow[tel];?></span></td> <td bgcolor="#FFFFFF"><span><?php echo $myrow[address];?></span></td> </tr> <?php }}?> </table> <form method="get" action="index.php" onSubmit="return chk(this)"> <table cellpadding="0" cellspacing="0" bgcolor="#11DFF0"> <tr> <td valign="middle"><span>&nbsp;&nbsp;页次:<?php echo $_GET['page'];?> / <?php echo $page_count;?> 页 记录:<?php echo $message_count;?> 条 </span></td> <td valign="middle"><span> &nbsp;分页: <?php if($_GET['page']!=1) { echo "<a href=index.php?page=1>首页</a>&nbsp;"; echo "<a href=index.php?page=".($_GET['page']-1).">上一页</a>&nbsp;"; } if($_GET['page']<$page_count) { echo "<a href=index.php?page=".($_GET['page']+1).">下一页</a>&nbsp;"; echo "<a href=index.php?page=".$page_count.">尾页</a>"; if($_GET['page']<= $page_count and $_GET['page']>0) { echo "<a href=index.php?page=".$_GET['page']."></a>"; } } ?> <input type="text" size="3"> <input type="hidden" value="<?php echo $page_count;?>"> <input type="submit" value="跳转"> </span> </td> </tr> </table> </form> </body> </html>

二、运行结果

PHP+MySQL实现输入页码跳转到指定页面功能示例

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a1bb8ee270b0f8f8de4d0c3ff27f61f6.html