资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php怎么实现简单的雇员管理系统

这篇文章主要讲解了“php怎么实现简单的雇员管理系统”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“php怎么实现简单的雇员管理系统”吧!

成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的饶平网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

  这是一个简单的php练习小项目,因为比较简单所以就没有用Smarty模板去把这个项目彻底的输入,处理,输出分离,只是简单的用MVC的设计模式去写的。这个项目主要是为了练习Cookie和Session的使用。

  数据库用的是MySQL,建了一个empmanage的数据库,里面有两张表。如图:

php怎么实现简单的雇员管理系统  

表的结构如图:

php怎么实现简单的雇员管理系统

php怎么实现简单的雇员管理系统

  php怎么实现简单的雇员管理系统

  这是登陆界面,因为主要想练习后台相关知识,所以前台页面写的比较简单。实际上是先写的index.php,里面就只是一个跳转。

 index.php

  login.php




emp_system


emp login

用户名"/>
密码 
sava cookie
输入的密码或用户名错误,错误信息".$errNo; } ?>

  login.php中require_once的common.php

  login.php中表单提交到loginProcess.php去。

checkUser($username, $password)){
		//合法	
		session_start();
		$_SESSION['id']=$id;
		header("Location:Main.php?id=$id");
		exit();
		
	}else{
		//非法
		header("Location:login.php?errNo=2");
		exit();
	}
	

?>

  loginProcess中require_once的adminService.class.php。

execute_dql($sql);

			if($row=mysql_fetch_assoc($res)){
				if($row['password']==md5($password)){
					$id=$row['id'];
					return $id;
				}else{
					return null;
				}
			}else{
					return null;
			}
			//释放资源
			mysql_free_result($res);
			//关闭连接
			$sqlHelper->close_connent();
		}
			
	}
?>

  adminService.class.php中require_once的SqlHelper.class.php。

host,$this->username,$this->password);
			if(!$conn){
				die("connect error".mysql_errno());
			}
			mysql_select_db($this->dbname) or die(mysql_errno());
			//mysql_query("set names utf8",$this->conn);
		}
		//dql
		public function execute_dql($sql){
			
			$res=mysql_query($sql) or die(mysql_error());
			
			return $res;
		}
		//dql2 返回一格数组 可以直接关闭结果集
		public function execute_dql2($sql){
			$arr=array();
			$i=0;
			$res=mysql_query($sql) or die(mysql_error());
			while($row=mysql_fetch_assoc($res)){
				$arr[$i++]=$row;
			}
			mysql_free_result($res);
			return $arr;
		}
		//分页查询
		public function execute_dql_fenye($sql1,$sql2,$fenyePage){
			$res=mysql_query($sql1) or die(mysql_error());
			$arr=array();
			while($row=mysql_fetch_assoc($res)){
				$arr[]=$row;
			}
			mysql_free_result($res);
			$fenyePage->res_array=$arr;
			
			$res2=mysql_query($sql2) or die(mysql_error());
			if($row=mysql_fetch_row($res2)){
				$fenyePage->rowCount=$row[0];
				$fenyePage->pageCount=ceil($row[0]/$fenyePage->pageSize);
			}
			mysql_free_result($res2);
			$daohangtiao="";
			if($fenyePage->pageNow>1){
				$prePage=$fenyePage->pageNow-1;
				$fenyePage->daohangtiao= "gotoUrl}?pageNow=$prePage'>上一页";
			}
			if($fenyePage->pageNow<$fenyePage->pageCount){
				$nextPage=$fenyePage->pageNow+1;
				$fenyePage->daohangtiao.= "gotoUrl}?pageNow=$nextPage'>下一页";
			}
			//用for打印10页超链接
			$start=floor(($fenyePage->pageNow-1)/10)*10+1;
			$index=$start;
			if($fenyePage->pageNow>10){			
				$fenyePage->daohangtiao.= " gotoUrl}?pageNow=".($start-1)."'><<";
			}
			for(;$start<$index+10;$start++){
				$fenyePage->daohangtiao.= "gotoUrl}?pageNow=$start'>[$start]";
			}
				$fenyePage->daohangtiao.= " gotoUrl}?pageNow=$start'>>>";
				$fenyePage->daohangtiao.= " 当前{$fenyePage->pageNow}页/共{$fenyePage->pageCount}页";
			
		}
		
		//dml
		public function execute_dml($sql){
			$res=mysql_query($sql) or die(mysql_error());
			if(!$res){
				return 0;//没有用户匹配
			}
			if(mysql_affected_rows($this->conn)>0){
				return 1;//ok
			}else{
				return 2;//没有行受到影响
			}
		}
		//关闭连接
		public function close_connent(){
			if(!empty($this->conn)){
				mysql_close($this->conn);
			}
		}
	}	
?>

  验证是合法用户跳转到Main.php,非法跳转到login.php并把errNo带回去并用红色输出。如图:






Main View

管理用户
添加用户
查询用户

php怎么实现简单的雇员管理系统

php怎么实现简单的雇员管理系统

  在Main页面你可以选择管理用户,添加用户,查询用户(用户可以理解为雇员)。那么点击查询用户后会跳转到selectEmp.php去。

php怎么实现简单的雇员管理系统





查找用户

输入id号:

  在selectEmp.php中的表单会跳转到empProcess.php去。

deleteById($id)==1){
				header("Location: ok.php");
				exit();
			}else{
				header("Location: err.php");
				exit();
			}
		
		}else if($_REQUEST['flag']=="addEmp"){
			$name=$_REQUEST['name'];
			$grade=$_REQUEST['grade'];
			$email=$_REQUEST['email'];
			$salary=$_REQUEST['salary'];
			if($empService->addEmp($name, $grade, $email, $salary)==1){
				header("Location: ok.php");
				exit();
			}else{
				header("Location: err.php");
				exit();
			}
		}else if($_REQUEST['flag']=="selectEmp"){
			$id=$_REQUEST['id'];			
			if($res=$empService->selectEmp($id)){
				echo "id{$res[0]['id']} name{$res[0]['name']} grade{$res[0]['grade']} email{$res[0]['email']} salary{$res[0]['salary']}";
			}
		}else if($_REQUEST['flag']=="updataEmp"){
			$id=$_REQUEST['id'];
			$name=$_REQUEST['name'];
			$grade=$_REQUEST['grade'];
			$email=$_REQUEST['email'];
			$salary=$_REQUEST['salary'];
			if($empService->updataEmp($id, $name, $grade, $email, $salary)==1){
				header("Location: ok.php");
				exit();
			}else{
					header("Location: err.php");
					exit();
			}
		}
	}
?>

  这其中require_once的empService.class.php和emp.class.php。

execute_dql($sql);
			if($row=mysql_fetch_row($res)){
				$rowCount=$row[0];
			}
			$pageCount=ceil($rowCount/$pageSize);
			mysql_free_result($res);
			$sqlHelper->close_connent();
			return $pageCount;
		}
		//取出结果集
		public function getRes($pageNow,$pageSize){
			$sqlHelper=new SqlHelper();
			$sql="select id,name,grade,email,salary from emp limit ".($pageNow-1)*$pageSize.",$pageSize";
			$res=$sqlHelper->execute_dql2($sql);
 			$sqlHelper->close_connent();
			return $res;
		}
		//分页
		public function getFenyePage($fenyePage){
			$sqlHelper=new SqlHelper();
			$sql1="select id,name,grade,email,salary from emp limit ".($fenyePage->pageNow-1)*$fenyePage->pageSize.",$fenyePage->pageSize";
			$sql2="select count(id) from emp";
			$sqlHelper->execute_dql_fenye($sql1, $sql2, $fenyePage);
			$sqlHelper->close_connent();
		}
		//删除用户
		public function deleteById($id){
			$sqlHelper=new SqlHelper();
			$sql="delete from emp where id=$id";
			return $sqlHelper->execute_dml($sql) or die(mysql_error());
			
			$sqlHelper->close_connent();	
		}
		//添加用户
		public function addEmp($name,$grade,$email,$salary){
			$sqlHelper=new SqlHelper();
			$sql="insert into emp(name,grade,email,salary) values ('$name','$grade','$email','$salary')";
			
			return $sqlHelper->execute_dml($sql) or die(mysql_error());	
			$sqlHelper->close_connent();
		}
		//查询用户
		public function selectEmp($id){
			$sqlHelper=new SqlHelper();
			$sql="select * from emp where id=$id";
			$res=$sqlHelper->execute_dql2($sql) or die(mysql_error());
			$sqlHelper->close_connent();
			return $res;
		}
		//修改用户
		public function updataEmp($id,$name,$grade,$email,$salary){
			$sqlHelper=new SqlHelper();
			$sql="update emp set name='$name',grade=$grade,email='$email',salary=$salary where id=$id";
			
			return $sqlHelper->execute_dml($sql) or die(mysql_error());
			$sqlHelper->close_connent();
		}
	}
?>

  验证后若该用户存在输出该用户的详细信息,如id name grade email salary。这是查询,因为做的比较简单,所以没有写个超链接让它返回上一层。

  若你在Main界面点击的是添加用户,则会跳转到addEmp.php。





添加用户

name
grade(tinyint)
email
salary(int)

php怎么实现简单的雇员管理系统

  为了简单没有用js正则表达式去对表单中所输入的内容进行验证是否符合格式。输入完表单后会跳转到empProcess.php去验证。如果添加成功会跳转到ok.php,否则会跳转到err.php。

返回上一级";

?>
";
	echo "返回上一级";
?>

  若在Main页面点击管理用户则会跳转到empList.php。

php怎么实现简单的雇员管理系统





pageNow=1;//显示第几页 用户输入 不停变化
	if(!empty($_GET['pageNow'])){
		$fenyePage->pageNow=$_GET['pageNow'];
	}
	$fenyePage->pageCount=0;//共几页 需要$rowCount计算
	$fenyePage->pageSize=5;//一页显示多少条记录
	$fenyePage->rowCount=0;//数据库中获取 共有几条记录
	$fenyePage->gotoUrl="empList.php";//要跳转的页面
	
	$empService=new empService();
	$empService->getFenyePage($fenyePage);
	echo "";
	echo "idnamegradeemailsalary删除用户修改用户";
	for($i=0;$ires_array);$i++){
		$row=$fenyePage->res_array[$i];
		
		echo "{$row['id']}{$row['name']}{$row['grade']}{$row['email']}{$row['salary']}删除用户修改用户";
	}
	echo "";
	//打印导航条
	echo $fenyePage->daohangtiao;
	

?>

  其中require_once的FenyePage.class.php。

 点击修改用户会跳转到updataEmp.php。





修改用户

id"/>
name"/>
grade(tinyint)"/>
email"/>
salary(int)"/>

php怎么实现简单的雇员管理系统

感谢各位的阅读,以上就是“php怎么实现简单的雇员管理系统”的内容了,经过本文的学习后,相信大家对php怎么实现简单的雇员管理系统这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


名称栏目:php怎么实现简单的雇员管理系统
URL标题:http://cdkjz.cn/article/pgisog.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220