php简单分页

王朝学院·作者佚名  2016-08-28
窄屏简体版  字體: 小  |  中  |  大  |  超大  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="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>

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航