php简单分页

2/11/2016来源:PHP技巧人气:1372

<!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=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
$conn=MySQL_connect("localhost","root","123");
mysql_select_db("QQ",$conn);
mysql_query("set names utf8");
$length=5;
$pagenum=isset($_GET['page'])?$_GET['page']:1;
$totsql="select count(*) from q1";
$totarr=mysql_fetch_row(mysql_query($totsql));
$pagetot=ceil($totarr[0]/$length);
if($pagenum>=$pagetot){
$pagenum=$pagetot;
}
$offset=($pagenum-1)*$length;
$sql="select * from q1 order by id limit {$offset},{$length}";
$ret=mysql_query($sql);
echo "<center>";
echo "<table width='700' border='1px'>";
while($row=mysql_fetch_assoc($ret)){
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['name']}</td>";
echo "<td>{$row['pass']}</td>";
echo "<tr>";
}
echo "</table>";
$PRevpage=$pagenum-1;
$nextpage=$pagenum+1;
echo "<h2><a href='feiye.php?page={$prevpage}'>上</a>|<a href='feiye.php?page={$nextpage}'>下</a></h2>";
echo "</center>";
mysql_close($conn);

 

?>
</body>
</html>