这个章节将讲解分层模式对雇员管理系统的系统,首先看下基本的流程图设计:



下面是具体的代码:

1、login.php(参照上节)
2、loginProcess.php
<?php
/**
*
* @author jsh
* @version
*/ require_once 'AdminService.class.php';
//接受用户数据
$id=$_POST['id'];
$password=$_POST['password']; //实例化对象
$adminService=new AdminService(); if(($name=$adminService->checkAdmin($id, $password)) != ""){
header("Location:https://192.168.1.110/myphp/manage/empManage.php?name=$name");
exit();
} else {
header("Location:https://192.168.1.110/myphp/manage/login.php?errno=1");
exit();
}
?>

3、empmain.php(参照上节)
4、empList.php
<html>
<head>
<meta http-equiv="content-tpe" content="text/html;charset-utf-8"/>
<title>雇员管理列表</title>
<script type="text/javascript">
<!--
function check(){
return window.confirm("是否要删除用户");
}
//-->
</script>
</head> <?php
include_once 'EmpService.class.php';
include_once 'FenyePage.class.php';
/*
$pageNow :显示第几页:用户输入
$pageCount:共有几页[]
$rowCount:共有多少条记录[数据库获取]
$pagesize:每页显示几条记录[人为定义]
*/ if(!empty($_GET['flag'])){
$id=$_GET['Id'];
$empservice=new empService();
$empservice->delUserById($id);
}
if(!empty($_GET['pageNow'])){
$pageNow = $_GET['pageNow'];
} else {
$pageNow = 1;
} $fenyePage=new fenyepage();
$fenyePage->pageSize = 3;
$fenyePage->pageNow = $pageNow;
$fenyePage->page_num=3; //获取共有多少记录
$empservice=new empService();
$pageCount=$empservice->getFenYePageInfo($fenyePage);
echo "<h1>雇员管理系统</h1>";
echo "<table width='700px' border='1px'>";
echo "<tr><th>Id</th><th>Name</th><th>Grade</th><th>Email</th><th>Salary</th><th>删除用户</th><th>修改用户</th></tr>"; for($i=0;$i<count($fenyePage->res_array);$i++){
$row=$fenyePage->res_array[$i];
echo "<tr><th>{$row['Id']}</th><th>{$row['Name']}</th><th>{$row['Grade']}</th>".
"<th>{$row['Email']}</th><th>{$row['Salary']}</th><th><a onclick='return check()' href='empList.php?flag=1&Id={$row['Id']}'>删除用户</a></th>".
"<th><a href='empList.php?pageNow={$row['Id']}'>修改用户</a></th></tr>";
}
echo "</table>"; echo $fenyePage->navigation_bars;
/* //打印上一页下一页
if($fenyePage->pageNow>1){
$prepage = $fenyePage->pageNow - 1;
echo "<a href='empList.php?pageNow=$prepage'>上一页</a>";
}
if($fenyePage->pageNow<$fenyePage->pageCount){
$nextpage = $fenyePage->pageNow + 1;
echo "<a href='empList.php?pageNow=$nextpage'>下一页</a>";
} //翻页
$start=floor(($fenyePage->pageNow - 1)/$fenyePage->page_num) * $fenyePage->page_num + 1;
$index = $start; for(;$start < $fenyePage->pageCount && $start<$index + $fenyePage->page_num;$start++){
echo "<a href='empList.php?pageNow=$start'>[$start]</a>";
}
//显示当前页和共有多少页
echo "  当前页{$fenyePage->pageNow}/共{$fenyePage->pageCount}页";
*/ ?>
<!-- 指定跳转到某页 -->
<form action="empList.php" method="get"> 跳转到:<input type="text" name="pageNow"/>
<input type="submit" value="GO"/>
</form> </html>

5、AdminService.class.php

<?php
//该类是一个业务逻辑处理类,
require_once 'SqlHelper.class.php';
class AdminService {
//提供一个验证用户是否合法的方法 public function checkAdmin($id,$password){
$sql="select * from admin where Id=$id"; //创建一个SqlHelper对象
$sqlHelper=new SqlHelper();
//执行查询命令
$res=$sqlHelper->execute_dql($sql);
if($row=mysql_fetch_assoc($res)){
if(md5($password) == $row['Password']){ return $row['Name'];
}
}
//释放资源
mysql_free_result($res);
//关闭链接
$sqlHelper->close_connect(); return "";
} } ?>

6、empService.class.php

<?php
require_once 'SqlHelper.class.php';
class empService { //一个函数可以获得多少页
function getPageCount($pagesize){
//需要查询$rowcount
$sql="select count(Id) from emp";
$sqlHelper=new SqlHelper();
$result=$sqlHelper->execute_dql($sql); if($row=mysql_fetch_row($result)){
$pageCount=ceil($row[0]/$pagesize);
}
//释放资源
mysql_free_result($result);
//关闭连接
$sqlHelper->close_connect();
return $pageCount;
} //获得当前页的雇员信息
function getEmpListByPage($pageNow,$pageSize){
$sql="select * from emp limit ".($pageNow-1)*$pageSize.",$pageSize"; $sqlHelper=new SqlHelper();
$res=$sqlHelper->execute_dql2($sql); //关闭连接
$sqlHelper->close_connect(); return $res;
}
//分页
public function getFenYePageInfo($fenyePage){
$sqlHelper=new SqlHelper();
$sql1="select * from emp limit ".($fenyePage->pageNow - 1)*$fenyePage->pageSize.",$fenyePage->pageSize";
$sql2="select count(Id) from emp";
$php_name="empList.php";
$sqlHelper->exectue_dql_fenye($sql1, $sql2, $fenyePage,$php_name);
//关闭链接
$sqlHelper->close_connect();
return $fenyePage; } //删除用户
public function delUserById($id){
$sql="delete from emp where Id='$id'";
$sqlHelper = new SqlHelper();
$res=$sqlHelper->execute_dml($sql);
return $res;
}
}
?>

7、SqlHelper.class.php

<?php
//这是一个工具类,作用是完成对数据库的基本操作
class SqlHelper {
public $conn;
public $dbname="manage";
public $usename="root";
public $password="";
public $host="192.168.1.110:3306"; //构造方法,连接及选择数据库
public function __construct(){
$this->conn=mysql_connect($this->host,$this->usename,$this->password);
if(!$this->conn){
die("连接失败".mysql_error());
}
mysql_select_db($this->dbname,$this->conn);
} //执行dql语句 查询
public function execute_dql($sql){
$res=mysql_query($sql,$this->conn) or die("执行失败".mysql_error());
return $res;
} //省去资源释放的
public function execute_dql2($sql){
$res=mysql_query($sql,$this->conn) or die("执行失败".mysql_error());
$arr=array();
$i=0;
while ($row=mysql_fetch_assoc($res)){ $arr[$i++]=$row;
}
//释放资源
mysql_free_result($res);
return $arr;
} /* 考虑分页情况的查询
$sql1="select count(Id) from 表名";
$sql2="select * from 表名 limit x,y"; */
public function exectue_dql_fenye($sql1,$sql2,&$fenyePage,$php_name){
$navigation_bars="";
$res=mysql_query($sql1,$this->conn) or die("执行失败".mysql_error());
$arr=array();
$i=0;
while ($row=mysql_fetch_assoc($res)){
$arr[$i++]=$row;
}
//释放资源
mysql_free_result($res); //获得数据库共有多少行
$res=mysql_query($sql2,$this->conn) or die(mysql_errno());
if($row=mysql_fetch_row($res)){
$fenyePage->row_Count=$row[0];
} $fenyePage->res_array=$arr;
//共有多少页
$fenyePage->pageCount = ceil($fenyePage->row_Count/$fenyePage->pageSize);
//释放资源
mysql_free_result($res); if($fenyePage->pageNow>1){
$prepage = $fenyePage->pageNow - 1;
$navigation_bars="<a href='$php_name?pageNow=$prepage'>上一页</a>";
}
if($fenyePage->pageNow<$fenyePage->pageCount){
$nextpage = $fenyePage->pageNow + 1;
$navigation_bars .= "<a href='$php_name?pageNow=$nextpage'>下一页</a>";
} //翻页
$start=floor(($fenyePage->pageNow - 1)/$fenyePage->page_num) * $fenyePage->page_num + 1;
$index = $start;
if($fenyePage->pageNow > $fenyePage->page_num){
$navigation_bars .="<a href='$php_name?pageNow=".($start-1)."'> << </a>";
}
for(;$start < $fenyePage->pageCount && $start<$index + $fenyePage->page_num;$start++){
$navigation_bars .= "<a href='$php_name?pageNow=$start'>[$start]</a>";
}
$navigation_bars .="<a href='$php_name?pageNow=".($start+1)."'> << </a>";
//显示当前页和共有多少页
$navigation_bars .= "  当前页{$fenyePage->pageNow}/共{$fenyePage->pageCount}页";
$fenyePage->navigation_bars=$navigation_bars;
} //执行DML语句 更新 删除 添加
public function execute_dml($sql){
$b=mysql_query($sql,$this->conn);
if(!$b){
return 0;//失败
} else {
if(mysql_affected_rows($this->conn)){
return 1;//执行成功
}else{
return 2;//表示没有行发生变化
}
}
} //关闭连接的方法
public function close_connect(){
if($this->conn){
mysql_close($this->conn);
}
}
}
?>

8、fenyepage.class.php

<?php
class fenyepage{
public $pageSize; //每页显示的行数
public $pageNow; //当前页
public $pageCount; //共有多少页。计算得到
public $res_array;//显示数据,数据库获得
public $row_Count; //共有多少行,数据库获得
public $page_num; //翻页数
public $navigation_bars;//导航条
}
?>

下面展示的是一个主要的页面:



PHP自学之路---雇员管理系统(2)的更多相关文章

  1. PHP自学之路---雇员管理系统(1)

    前面已经介绍了Zend studio工具的使用以及软件开发的基本阶段,下面就是我们第一个练习,雇员管理系统,从设计到实现来简单介绍下: 开发环境: 服务器:基于Linux 2.618环境下配置PHP服 ...

  2. 【转】JAVA自学之路

    JAVA自学之路 一: 学会选择 为了就业,不少同学参加各种各样的培训. 决心做软件的,大多数人选的是java,或是.net,也有一些选择了手机.嵌入式.游戏.3G.测试等. 那么究竟应该选择什么方向 ...

  3. 我的.NET自学之路

    我第一门语言接触的并不是.net,而是php刚学php感觉还好,但是一学到后面就有一点头晕乎乎的,我感觉没有一个好的编写php代码的编辑器.而且php是弱类型语言,感觉起来没有像c,java,c#这些 ...

  4. EMS-Demo 雇员管理系统演示

    做了一个小小的雇员管理系统,主要使用了JTable,然后比较得意的地方是实现了拼音搜索,感觉很高大上其实只要引入一个Jpinyin.jar就可以了(网上到处都有下载或者去我的git项目的lib中下载) ...

  5. [php笔记]项目开发五个阶段/雇员管理系统

    zend 公司,管理PHP版本的升级. 功能强大, 官方推荐. (开发一个PHP项目) 软件开发的五个阶段. 1.创建一个项目(工程)2.设置该项目的路径3.创建一个文件test.php ***使用Z ...

  6. 聊聊我的 Java 自学之路

    最近经常在知乎收到类似『没基础,java 如何自学』.『怎么才能掌握编程』等等问题,再加上发现高中同学也在自学.有感而发,讲讲我的自学之路. 1.1. 大学 高考没正常发挥,考入一所二流的学校,当时分 ...

  7. 一个「学渣」从零开始的Web前端自学之路

    从 13 年专科毕业开始,一路跌跌撞撞走了很多弯路,做过餐厅服务员,进过工厂干过流水线,做过客服,干过电话销售可以说经历相当的“丰富”. 最后的机缘巧合下,走上了前端开发之路,作为一个非计算机专业且低 ...

  8. 【我的前端自学之路】【HTML5】.html和.htm的区别

    以下为自学笔记内容,仅供参考. 转发请保留原文链接:https://www.cnblogs.com/it-dennis/p/10508171.html .htm 和 .html 的区别 .htm 和 ...

  9. 【转】Java自学之路——by马士兵

    作者:马士兵老师 JAVA自学之路 一:学会选择 为了就业,不少同学参加各种各样的培训. 决心做软件的,大多数人选的是java,或是.net,也有一些选择了手机.嵌入式.游戏.3G.测试等. 那么究竟 ...

随机推荐

  1. MVC应用程序使用Wcf Service

    原文:MVC应用程序使用Wcf Service 前一篇Insus.NET有演示过MVC应用程序使用Web Service, 此篇Insus.NET想继续演示Service,不过是WCF Service ...

  2. Python 静态变量 与 静态方法

    静态变量: XXXClass.py: class XXXClass: CONST_Value = 10.1 Tester.py: import XXXClass print XXXClass.XXXC ...

  3. PHP+Mysql+jQuery实现中国地图区域数据统计(raphael.js)

    使用过百度统计或者cnzz统计的童鞋应该知道,后台有一个地图统计,不同访问量的省份显示的颜色也不一样,今天我将带领大家开发一个这样的案例.上一篇<使用raphael.js绘制中国地图>文章 ...

  4. 在VirtualBox下安装CentOS教程(截图版)

    http://blog.csdn.net/kobe_lzq/article/details/7894718 使用的软件: VirtualBox 4.1.2 CentOS 5.6 x86_64  刻录的 ...

  5. ReSharper 8.1支持Visual Studio 2013的特色——超强滚动条

    自ReSharper 8.1发布以来,便支持Visual Studio 2013.其中peek功能是它的亮点,滚动条则是它的特色. 接下来小编将展示ReSharper在Visual Studio 20 ...

  6. artTemplate模板

    1.介绍 新一代 javascript 模板引擎. 2.性能(引) 1.性能卓越,执行速度通常是 Mustache 与 tmpl 的 20 多倍(性能测试) 2.支持运行时调试,可精确定位异常模板所在 ...

  7. jQueryRotate 转盘抽奖代码实现

    代码如下: 例子兼容IE6,7,8 以及高版本浏览器,如有bug请回复! 1.html结构 <!doctype html> <html lang="en"> ...

  8. 通过如何通过js实现复制粘贴功能

    在ie中window.clipboardData(剪切板对象)是可以被获取,所以利用这个方法我们可以实现在IE当中复制粘贴的功能,demo如下! <html> <head> & ...

  9. springmvc和servlet在上传和下载文件(保持文件夹和存储数据库Blob两种方式)

    参与该项目的文件上传和下载.一旦struts2下完成,今天springmvc再来一遍.发现springmvc特别好包,基本上不具备的几行代码即可完成,下面的代码贴: FileUpAndDown.jsp ...

  10. Effective C++ Item 46 当需要投你非成员函数定义模板

    本文senlie原版的,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:当我们编写一个 class template, 而它所提供之"与此 temp ...