05-php雇员管理系统-实现显示雇员信息列表分页

empList.php

<html>

<head>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
<title>雇员信息列表</title>
</head>

<?php
$conn = mysql_connect ( "localhost", "root", "root" ) or die ( mysql_error () );
mysql_query ( "set names utf8" );
//选择数据库
mysql_select_db ( "test", $conn );

$pageSize=3;//每页数
$rowCount=0;//记录数
$pageNow=1;//当前页
$pageCount=0;//页数
 

//根据用户的点击收取pagenow的值
if(!empty($_GET['pageNow'])){
	$pageNow=$_GET['pageNow'];
}

$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 width='700px' border='1px'>";
echo "<tr><th>id</th><th>name</th><th>grade</th>";
echo "<th>email</th><th>salary</th><td colspan='2'>操作</td></tr>";
//这里我们需要循环显示用户的信息
while ( $row = mysql_fetch_assoc ( $res2 ) ) {
	echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['grade']}</td>";
	echo "<td>{$row['email']}</td><td>{$row['salary']}</td>";
	echo "<td><a href='#'>删除用户</a></td>";
	echo "<td><a href='#'>修改用户</a></td><tr>";
}
echo "<h1>雇员信息列表</h1>";
echo "<hr/>";
echo "</table>";
//打印页码的超链接
for ($i = 1; $i <= $pageCount; $i++) {
	echo "<a href='empList.php?pageNow=$i'>$i</a> ";
}


//关闭资源
mysql_free_result($res2);
mysql_close($conn);
?>
</html>
empManage.php

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<?php
echo "欢迎你," . $_GET ['name'] . "登录成功!...";
echo "<br/><a href='login.php'>返回重新登录</a>";
?>
<h1>主界面</h1>
<a href="empList.php">管理用户</a>
<br />
<a href="#">添加用户</a>
<br />
<a href="#">查询用户</a>
<br />
<a href="#">退出系统</a>
<br />
</html>

loginProcess.php

<?php

//接受用户的数据
//1.id
$id = $_POST ['id'];
//2.密码
$password = $_POST ['password'];

//得到连接
$conn = mysql_connect ( "localhost", "root", "root" );
if (! $conn) {
	die ( "连接失败" . mysql_errno () );
}
//设置访问数据库的编码
mysql_query ( "set names utf8", $conn ) or die ( mysql_errno () );
//选择数据库
mysql_select_db ( "test", $conn ) or die ( mysql_errno () );
//发送sql语句验证
$sql = "select password,name from admin where id=$id";
//通过id获取password
$res = mysql_query ( $sql, $conn );
if ($row = mysql_fetch_assoc ( $res )) {
	//取出数据库的密码
	if ($row ['password'] == md5 ( $password )) {
		//合法
		//取出用户名字
		$name=$row['name'];
		header ( "Location:empManage.php?name=$name" );
		exit ();
	}
}
header ( "Location:login.php?errno=1" );
exit ();

//关闭资源
mysql_free_result($res);
mysql_close($conn);

?>

login.php

<html>

<head>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
</head>
<h1>管理员登录系统</h1>
<form action="loginProcess.php" method="post">
<table>
	<tr>
		<td>用户id</td>
		<td><input type="text" name="id" /></td>
	</tr>
	<tr>
		<td>密  码</td>
		<td><input type="password" name="password" /></td>
	</tr>
	<tr>
		<td><input type="submit" value="用户登录" /></td>
		<td><input type="reset" value="重新填写" /></td>
	</tr>
</table>
</form>
<?php 
if(!empty($_GET['errno'])){
	 $errno=$_GET['errno'];
	 if($errno==1){
	 	echo "<font color='red' size='3'>你的用户名或密码错误</font>";
	 }
}
   
?>
</html>



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会编程的阿强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值