试题图片:thinkphp机试题目1(员工信息管理系统) 附完整答案thinkphp机试题目1(员工信息管理系统) 附完整答案thinkphp机试题目1(员工信息管理系统) 附完整答案thinkphp机试题目1(员工信息管理系统) 附完整答案thinkphp机试题目1(员工信息管理系统) 附完整答案

数据库代码:create database dept DEFAULT charset=utf8;
use dept;
create table tbl_dept(
       dept_id int primary key AUTO_INCREMENT,
       dept_name varchar(30),
       dept_office varchar(10)
);
insert into tbl_dept values(1,'市场部','1705');
insert into tbl_dept values(2,'财务部','1704');
insert into tbl_dept values(3,'采购部','1801');
insert into tbl_dept values(4,'技术支持部','1205');
select * from tbl_dept;
create table tbl_emp(
       emp_id int primary key AUTO_INCREMENT,
       emp_name varchar(20),
       dept_id varchar(20),
       emp_gender varchar(3)
);
insert into tbl_emp values(1001,'周伯通','4','男');
insert into tbl_emp values(1002,'欧阳锋','1','男');
insert into tbl_emp values(1003,'洪七公','4','女');
insert into tbl_emp values(1004,'杨过','3','男');
select * from tbl_emp;


控制器代码:

<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
    public function index(){
$m=M("tbl_emp");
if($_POST){
$emp_id=$_POST["emp_id"];
$emp_name=$_POST["emp_name"];
}
$data=array();
if($emp_id){
$data["emp_id|emp_name"]=array("like","%$emp_id%");
}
$this->assign("emp_id",$emp_id);
$this->assign("emp_name",$emp_name);
//echo $emp_id;
$arr=$m->join('left JOIN tbl_dept ON tbl_emp.dept_id = tbl_dept.dept_id')->where($data)->select();
$this->assign("arr",$arr);
$this->display();
    }
public function index_add(){
$m=M("tbl_emp");
if($_POST){
$data['emp_name']  = $_POST["emp_name"];
$data['emp_gender']  = $_POST["emp_gender"];
$data['dept_id']  = $_POST["dept_id"];
$res=$m->add($data);
if($res>0){
$this->success("添加成功");
}else{
$this->error("添加失败");
}
}else{
$m2=M("tbl_dept");
$arr2=$m2->select();
$this->assign("arr2",$arr2);
$this->display();
}
    }


}


视图代码:index.html


<!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>
<a href="__URL__/index_add">新增</a>
<form action="" method="POST">
请输入员工姓名或编号:<input type="text" name="emp_id" value="{$emp_id}"/>
    <input type="submit" value="查询"/>
</form>
<table border="1">
<tr>
    <td>员工姓名:</td>
        <td>性别:</td>
        <td>部门名称:</td>
        <td>办公室:</td>
    </tr>
    <volist name="arr" id="vo">
        <tr>
            <td>{$vo.emp_name}</td>
            <td>{$vo.emp_gender}</td>
            <td>{$vo.dept_name}</td>
            <td>{$vo.dept_office}</td>
        </tr>
    </volist>
</table>
</body>
</html>


视图代码:index_add.html


<!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>
<form action="" method="post">
    <table border="1">
        <tr>
            <td>员工姓名</td>
            <td><input type="text" name="emp_name"/></td>
        </tr> 
        <tr>
            <td>员工姓别</td>
            <td>
                <input type="radio" name="emp_gender" value="男"/>男
                <input type="radio" name="emp_gender" value="女"/>女
            </td>
        </tr> 
         <tr>
            <td>部门</td>
            <td>
                <select name="dept_id">
                    <option value="0">请选择</option>
                    <volist name="arr2" id="vo">
                    <option value="{$vo.dept_id}">{$vo.dept_name}</option>
                    </volist>
                </select>
            </td>
        </tr> 
        <tr>
            <td colspan="2">
            <input type="submit" value="提交"/>
                <a href="__URL__/index"><button>返回</button></a>
            </td>
        </tr> 
    </table>
</form>
</body>
</html>

相关文章:

  • 2021-12-26
  • 2021-10-09
  • 2021-12-19
  • 2021-09-28
  • 2021-06-26
  • 2022-01-25
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2021-07-21
  • 2022-12-23
  • 2021-05-28
  • 2021-05-19
  • 2021-07-28
  • 2021-05-04
  • 2022-12-23
相关资源
相似解决方案