您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2026/1/15 14:45:38发布20次查看
这篇文章主要介绍了php+mysql实现输入页码跳转到指定页面功能,结合实例形式分析了php连接mysql数据库进行数据查询及分页显示、指定页数跳转显示等相关操作技巧,需要的朋友可以参考下
本文实例讲述了php+mysql实现输入页码跳转到指定页面功能。分享给大家供大家参考,具体如下:
一、代码
conn.php:
<?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 width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#11dff0"> <tr> <td width="100" height="25" align="center" bgcolor="#11dff0" class="style2">姓名</td> <td width="100" align="center" bgcolor="#11dff0" class="style2">编号</td> <td width="125" align="center" bgcolor="#11dff0" class="style2">电话</td> <td width="175" align="center" bgcolor="#11dff0" class="style2">地址</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 height="25" align="center" bgcolor="#ffffff"><span class="style2"><?php echo $myrow[name];?></span></td> <td align="center" bgcolor="#ffffff"><span class="style2"><?php echo $myrow[number];?></span></td> <td align="center" bgcolor="#ffffff"><span class="style2"><?php echo $myrow[tel];?></span></td> <td align="center" bgcolor="#ffffff"><span class="style2"><?php echo $myrow[address];?></span></td> </tr> <?php }}?> </table> <form name="form1" method="get" action="index.php" onsubmit="return chk(this)"> <table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#11dff0"> <tr> <td width="42%" align="center" valign="middle"><span class="style1"> 页次:<?php echo $_get;?> / <?php echo $page_count;?> 页 记录:<?php echo $message_count;?> 条 </span></td> <td width="58%" height="28" align="left" valign="middle"><span class="style1"> 分页: <?php if($_get['page']!=1) { echo "<a href=index.php?page=1>首页</a> "; echo "<a href=index.php?page=".($_get['page']-1).">上一页</a> "; } if($_get['page']<$page_count) { echo "<a href=index.php?page=".($_get['page']+1).">下一页</a> "; 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 name="page" type="text" size="3"> <input type="hidden" name="pages" value="<?php echo $page_count;?>"> <input type="submit" name="submit" value="跳转"> </span> </td> </tr> </table> </form> </body> </html>
二、运行结果
相关推荐:
php+mysql实现登录注册修改密码网页
php+mysql实现从数据库获取下拉树功能的方法
php+mysql实现读写分离实战详解
以上就是php+mysql实现输入页码跳转到指定页面功能示例的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product