fenye.php
来源:互联网 发布:萧亚轩 知乎 男友 编辑:程序博客网 时间:2024/05/22 02:13
<html>
<head>
<title>php分页示例</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<?php
mysql_connect("localhost","root","12345678") or die(mysql_error());
//设定每一页显示的记录数
$pagesize = 1;
mysql_select_db("fqwh") or die(mysql_error());
//取得记录总数$rs,计算总页数用
$rs=mysql_query("select count(*) from usr",$conn);
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
//计算总页数
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
//设置页数
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
//设置为第一页
$page=1;
}
//计算记录偏移量
$offset=$pagesize*($page - 1);
//读取指定记录数
$rs=mysql_query("select * from usr order by id desc limit $offset,$pagesize",$conn);
if ($myrow = mysql_fetch_array($rs))
{
$i=0;
?>
<table border="0" width="80%">
<tr>
<td width="50%" bgcolor="#E0E0E0">
<p align="center">id</td>
<td width="50%" bgcolor="#E0E0E0">
<p align="center">name</td>
</tr>
<?php
do {
$i++;
?>
<tr>
<td width="50%"><?=$myrow["id"]?></td>
<td width="50%"><?=$myrow["name"]?></td>
</tr>
<?php
}
while ($myrow = mysql_fetch_array($rs));
echo "</table>";
}
echo "<div align='center'>共有".$pages."页(".$page."/".$pages.")";
for ($i=1;$i< $page;$i++)
echo "<a href='fenye.php?page=".$i."'>[".$i ."]</a> ";
echo "[".$page."]";
for ($i=$page+1;$i<=$pages;$i++)
echo "<a href='fenye.php?page=".$i."'>[".$i ."]</a> ";
echo "</div>";
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page > 1)
{
echo "<a href='fenye.php?page=".$first."'>首页</a> ";
echo "<a href='fenye.php?page=".$prev."'>上一页</a> ";
}
if ($page < $pages)
{
echo "<a href='fenye.php?page=".$next."'>下一页</a>";
echo "<a href='fenye.php?page=".$last."'>尾页</a> ";
}
?>
</body>
</html>
- fenye.php
- fenye.php
- fenye
- second6 fenye
- second7 fenye
- PHP
- PHP
- php
- php
- PHP
- PHP
- php
- php
- php
- PHP
- php
- php
- php
- res目录资源文件作用和命名方法
- Android UI【Android 仿Iphone文件夹分裂效果】
- listuser
- 利用python的xmllib2实现XML文件解析
- 程序员-不要做敲代码的机器
- fenye.php
- addUser.php
- deleteuser.php
- 基础备忘:数组指针与对一维数组名取地址
- (调试) tips
- 取石子游戏(威佐夫博奕)
- 关于求虚函数的和虚继承中的大小
- eclipse中, System.out.println() 快捷键
- deleteform.php