标签:
<!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>
<h2>分页查询<h2/>
<form action="fenye.php" method="get">
<table border="1" bordercolor="#FF0000">
<?php
class page
{
private $pagesize;
public $absolutepage;
private $pagecount;
private $totaINum;
private $prevpage;
private $nextpage;
function page($pagesize,$absolutepage)
{
$this->pagesize=$pagesize;
$this->absolutepage=$absolutepage;
}
public function listinfo()
{
$con=mysql_connect("localhost","root","120911");
if(!$con)
{
die(‘连接失败:‘.mysql_error);
}
if(!mysql_select_db("mydb",$con))
{
die(‘选择数据库失败:‘.mysql_error);
}
$result=mysql_query("select*from Persons");
mysql_close($con);
//所查询表中的总条数
$this->totaINum=mysql_num_rows($result);
//计算总页数
$this->pagecount=(int)(($this->totaINum-1)/($this->pagesize))+1;
//is_numeric检测变量是否为数字.absoulutepage为当前页
if($this->absolutepage==""||!is_numeric($this->absolutepage))
{
$this->absolutepage=1;
}
if($this->absolutepage>$this->pagecount)
{
$this->absolutepage=$this->pagecount;
}
if($this->totaINum>1&&$this->absolutepage>1)
{
$this->prevpage=$this->absolutepage-1;
}
if($this->absolutepage>=1&&$this->absolutepage<$this->pagecount)
{
$this->nextpage=$this->absolutepage+1;
}
?>
<tr align="center">
<td>ID</td>
<td>姓</td>
<td>名</td>
<td>年龄</td>
</tr>
<?php
if(mysql_data_seek($result,($this->absolutepage-1)*$this->pagesize))
{
for($i=0;$i<$this->pagesize;$i++)
{
if($info=mysql_fetch_array($result))
{
?>
<tr align="center">
<td><?php echo $info["personID"];?></td>
<td><?php echo $info["FirstName"];?></td>
<td><?php echo $info["LastName"];?></td>
<td><?php echo $info["Age"];?></td>
</tr>
<?php
}
}
}
}
public function toPage()
{
?>
<tr>
<td colspan="5">
一共<?php echo $this->totaINum ?>个学生,第<?php echo $this->absolutepage?>页/共
<?php echo $this->pagecount?>页:
<?php
echo "<a href=‘?absolutepage=1‘>首页</a>";
echo "<a href=‘?absolutepage=$this->prevpage‘>上一页</a>";
echo "<a href=‘?absolutepage=$this->nextpage‘>下一页</a>";
echo "<a href=‘?absolutepage=$this->pagecount‘>末页</a>";
?>
</td>
</tr>
<?php
}
}
//$obj=new page(3,$_GET[absolutepage]);
$obj=new page(3,$_GET[‘absolutepage‘]);
$obj->listinfo();
$obj->toPage();
?>
</table>
</form>
Undefined index: 参数未传过来<br>
Use of undefined constant:书写不规范
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/275147378abc/p/4804968.html