<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8/">
<title>雇员信息列表</title>
</head>
<?php
//查询数据
$conn=mysql_connect("localhost","root","1234567");
if(!$conn)
{
die("连接失败".mysql_errno());
}
//2.设置数据库的编码
mysql_query("set names utf8",$conn) or die (mysql_errno());
//3.选择数据库
mysql_select_db("empmanage",$conn) or die(mysql_errno());
//分页
$pageSize=3;
$rowCount=0;
$pageNow=1;
//在此我们需要根据用户的点击来修改pageNow的值,不要判断是否有这个pageNow发送
if(!empty($_GET['pageNow'])){
$pageNow=$_GET['pageNow'];
}
$pageCount=0;
$sql="select count(id) from emp";
$res1=mysql_query($sql);
//取出行数
if($row=mysql_fetch_row($res1)){
$rowCount=$row[0];
}
//计算共有多少页?
$pageCount=ceil($rowCount/$pageSize);
$sql="select * from emp limit ".($pageNow-1)*$pageSize.",$pageSize";
$res2=mysql_query($sql,$conn);
echo "<table border='1' bordercolor='green' cellspacing='0px' width='700px'>";
echo "<tr><th>id</th><th>name</th><th>grade</th>.
<th>email</th><th>salary</th><th>删除用户</th><th>修改用户</th></tr>";
//这是我们需要循环显示用户的信息;
while($row=mysql_fetch_assoc($res2))
{
echo "<tr><td>{$row['id']}</td><td>{$row['name']}.
</td><td>{$row['grade']}</td><td>{$row['email']}</td><td>{$row['salary']}</td><td><a href='#'>删除用户</a></td><td><a href='#'>修改用户</a></td></tr>";
}
echo "<h1>雇员信息列表</h1>";
echo "</table>";
//打印出页码的超链接
// for($i=1;$i<=$pageCount;$i++)
// {
// echo "<a href='empList.php?pageNow=$i'>$i</a> ";
// }
//显示上一页和下一页
if($pageNow>1){
$prePage=$pageNow-1;
echo "<a href='empList.php?pageNow=$prePage'>上一页</a> ";
}
if($pageNow<$pageCount){
$nextPage=$pageNow+1;
echo "<a href='empList.php?pageNow=$nextPage'>下一页</a> ";
}
//显示当前多少页
echo "当前{$pageNow}页/共{$pageCount}页";
//指定到跳转页
echo "<br/><br/>";
?>
<form action="emplist.php">
跳转到:<input type="text" name="pageNow"/>
<input type="submit" value="GO"/>
</form>
<?php
//关闭资源
mysql_free_result($res1);
mysql_free_result($res2);
mysql_close($conn);
?>
</html>
- 1
- 2
- 3
- 4
- 5
前往页