PHP+MySQL implements the example of jumping to a specified page by inputting a page number

不言
Release: 2023-03-29 07:54:02
Original
1749 people have browsed it

This article mainly introduces PHP MySQL to implement the function of jumping to a specified page by inputting a page number. It analyzes related operation skills such as connecting PHP to the mysql database for data query and paging display, specifying page number jump display, etc. in the form of examples. Required Friends can refer to

. The example in this article describes how PHP MySQL implements the function of jumping to a specified page by inputting a page number. Share it with everyone for your reference, the details are as follows:

1. Code

conn.php:

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

index.php:

<?php session_start();include("conn/conn.php"); if ($_GET[&#39;page&#39;]=="") {$_GET[&#39;page&#39;]=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[&#39;page&#39;]){
 $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[&#39;page&#39;]-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[&#39;page&#39;]!=1)
 {
  echo "<a href=index.php?page=1>首页</a> ";
  echo "<a href=index.php?page=".($_GET[&#39;page&#39;]-1).">上一页</a> ";
 }
 if($_GET[&#39;page&#39;]<$page_count)
 {
  echo "<a href=index.php?page=".($_GET[&#39;page&#39;]+1).">下一页</a> ";
  echo "<a href=index.php?page=".$page_count.">尾页</a>";
  if($_GET[&#39;page&#39;]<= $page_count and $_GET[&#39;page&#39;]>0)
  {
  echo "<a href=index.php?page=".$_GET[&#39;page&#39;]."></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>
Copy after login

2. Running results

Related recommendations:

php mysql realizes login registration and password modification webpage

##PHP Mysql method to achieve the drop-down tree function from the database

PHP MYSQL implementation of read-write separation practical detailed explanation

The above is the detailed content of PHP+MySQL implements the example of jumping to a specified page by inputting a page number. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!