当前位置: 首页 > 图文教程 > 网络编程 > PHP > php简单的分页程序

PHP
让我们来编写一些PHP实用的脚本
七种缓存使用武器 为网站应用和访问加速
动态网页PHP中引用&的使用注意事项
在PHP中全面阻止SQL注入式攻击
PHP自带可以代替echo调试的unit函数
小结:PHP动态网页程序优化及高效提速问题
php对特殊语句查询结果进行数组排序
实例:用PHP技术解决网站URL格式过长的问题
小结:PHP动态网页程序两个有用的小技巧
动态网页中直接不让访问PHP程序文件
网页实例:详细介绍用PHP来编写网页记数器
菜鸟学习:动态网页PHP基础学习笔记
利用Apache实现禁止图片盗链
PHP编程中常用的三则技巧
PHP制作的网站意见在线反馈表
大型Web需求解决方案 PHP定位突出
PHP实例:精确到每一秒钟的在线人数显示代码
实用:动态网页制作技术PHP的十个应用技巧
常见php页面漏洞分析及相关问题解决
PHP和MYSQL制作动态网站开发经验之谈

PHP 中的 php简单的分页程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 251 ::
收藏到网摘: n/a

php 分页 简单

[code]
<html>
<head>
<meta http-equiv="Content-Type" c>
<title>用户信息总汇</title>
<style type="text/css">
<!--
body,td,th {
font-size: 14px;
}
.STYLE1 {
font-size: 16px;
color: #666666;
}
-->
</style>
</head>
<body leftMargin=0 topMargin=0 rightmargin=0 >
<p>
<?php
#############################################################
########### 连接数据库 ################
#############################################################
$db=mysql_connect("192.168.0.2","root","goalwe608"); //数据库,用户名,密码
mysql_select_db("86pos",$db); //数据库
############# 分页 ############
//设定每一页显示的记录数
$pagesize=5;
//取得记录总数
$res=mysql_query("select count(id) from buyer " ,$db);
$myrow = mysql_fetch_array($res);
$numrows=$myrow[0];
//计算总页数
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
//判断页数设置与否,如无则定义为首页
if (!isset($page))
$page=1;
//防止恶意访问
if ($_GET php 分页 简单 >$pages)
$page=$pages;
if ($_GET php 分页 简单 <1)
$page=1;
if (!ereg("^[0-9]+$",$_GET php 分页 简单 ))
$page=1;
if ($_GET php 分页 简单 =="")
$page=1;

//计算记录偏移量
$offset=$pagesize*($page-1);
//取记录
$res=mysql_query("select username,pass,mail,add_time from buyer order by add_time limit $offset,$pagesize" ,$db);
//循环显示记录
if ($myrow = mysql_fetch_array($res))
{
$i=0;
?>
</p>
<p> </p>
<table width="100%" border="0" align="center">
<tr>
<td width="40%" height="30"> </td>
<td width="20%" align="center"><span class="STYLE1">用户信息管理<br>
<br>
</span></td>
<td width="15%"> </td>
<td><? $time=date ("Y-l-F H:i:s");echo $time;?>
</td>
</tr>
</table>
<div align="center">
-------------------------------------------------------------
</div>
<table width="90%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="10%" height="24" bgcolor="#cccccc"><div align="center">序号</div></td>
<td width="20%" bgcolor="#cccccc"><div align="center">用户名</div></td>
<td width="20%" bgcolor="#cccccc"><div align="center">密码</div></td>
<td width="30%" bgcolor="#cccccc"><div align="center">电子邮箱</div></td>
<td bgcolor="#cccccc"><div align="center">添加时间</div></td>
</tr>
<?php
do
{
$i++;
?>
<tr>
<td width="10%"><div align="center"><?php echo $i;?></div></td>
<td><div align="center"><font size="2"> <?php echo $myrow['username'];?></font></div></td>
<td><div align="center"><font size="2"><?php echo $myrow['pass'];?></font></div></td>
<td><div align="center"><font size="2"><?php echo $myrow['mail'];?></font></div></td>
<td><div align="center"><font size="2"><?php echo $myrow['add_time'];?></font></div></td>
</tr>
<?php
}
while ($myrow = mysql_fetch_array($res));
echo "</table>" ;
}
//显示总页数
echo "<div align='center'>共有".$pages."页(".$page."/".$pages.")<br>";
//显示分页数
for ($i=1;$i<$page;$i++)
echo "<a href='$SELF_PHP?page=".$i."'>第".$i ."页</a> ";
echo "第".$page."页 ";
for ($i=$page+1;$i<=$pages;$i++)
echo "<a href='$SELF_PHP?page=".$i."'>第".$i ."页</a> ";
echo "<br>";
//显示转到页数
echo "<form action='$SELF_PHP' method='post'> ";
//计算首页、上一页、下一页、尾页的页数值
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo "<a href='$SELF_PHP?page=".$first."'>首页</a> ";
echo "<a href='$SELF_PHP?page=".$prev."'>上一页</a> ";
}
if ($page<$pages)
{
echo "<a href='$SELF_PHP?page=".$next."'>下一页</a> ";
echo "<a href='$SELF_PHP?page=".$last."'>尾页</a> ";
}
echo "</form>";
echo "</div>";
?>
</table>
<p> </p>
</body>
</html>
[/code]