标签:des blog http io ar os sp on 数据
原文连接:http://www.cnblogs.com/xxcainiao/archive/2009/04/18/1438482.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>PHP分页</title>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","123456") or die("数据库连接错误".mysql_error());
mysql_select_db("wangyantest",$conn) or die("数据库访问错误".mysql_error());
mysql_query("set names gb2312");
$page=$_GET["page"];
if($page=="")
{$page=1;}
if(is_numeric($page))
{
$page_size=2; //每页多少条数据
$query="select count(*) as total from test order by id desc";
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$sql=mysql_query("select * from test order by id desc limit $offset,$page_size");
$row=mysql_fetch_object($sql);
if(!$row)
{
echo("暂无任何数据!");
}
?>
<ul>
<?php
do
{
?>
<li><?php echo "<a href=contnet.php?id=".$row->id.">". $row->titile."|".$row->content."</a>" ?></li>
<?php
}while($row=mysql_fetch_object($sql));
?>
</ul>
<?php
}
?>
当前页码:<?php echo $page;?>/<?php echo $page_count;?>
记录条数:<?php echo $message_count;?>
<hr/>
<?php
if($page!=1)
{
echo "<a href=page.php?page=1>首页</a> | ";
echo "<a href=page.php?page=".($page-1).">上一页</a> ";
}
if($page<$page_count)
{
echo "<a href=page.php?page=".($page+1).">下一页</a> | ";
echo "<a href=page.php?page=".$page_count.">尾页</a>";
}
mysql_free_result($sql);
mysql_close($conn);
?>
</body>
</html>
标签:des blog http io ar os sp on 数据
原文地址:http://www.cnblogs.com/webzhuo/p/4153236.html