Blogger Information
Blog 13
fans 0
comment 0
visits 12205
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php应用常规开发流程,课程作业,员工信息站点
小毛的博客
Original
932 people have browsed it

header.php//站点头部,包括数据与导航,数据较多,此处仅列出一行

<?php 
$staffs = [
	[
		'id'=>1,
		'name'=>'张三',
		'department'=>1,
		'image'=>'1.jpg',
		'detail'=>'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
	],
	。。。(略)
$departments = [
			['dep_id'=>1,'name'=>'hr','alias'=>'人力资源部'],
			['dep_id'=>2,'name'=>'fin','alias'=>'财务部'],
			['dep_id'=>3,'name'=>'market','alias'=>'***部'],
];
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<link rel="stylesheet" href="public/static/css/style.css">
	<title>员工信息</title>
</head>
<body>
	<!-- 头部导航 -->
	<div class="header">'
		<ul class="nav">
			<li><a href="index.php">全部信息 </a></li>
			<?php foreach($departments as $department) : ?>
			<li><a href="list.php?dep_id=<?php echo $department['dep_id']; ?>"><?php echo $department['alias']; ?></a></li>
			<?php endforeach; ?>
		</ul>
	</div>
	

index.php//首页(全员信息列表)

<?php 
include __DIR__.'/public/include/header.php';

foreach($departments as $department){
	
		echo "<h2>{$department['alias']}</h2>";
		echo '<ol>';	
		foreach ($staffs as $staff) {
		

			if($department['dep_id']==$staff['department']){
				echo "<li><a href='detail.php?id=".$staff['id']."'>{$staff['name']}</a></li>";
			}
		
		
	};
	echo '</ol>';
};
include __DIR__.'/public/include/footer.php';


 ?>

list.php//部门员工信息列表模板

<?php 
include __DIR__.'/public/include/header.php';
$dep_id = $_GET['dep_id'];
foreach($departments as $department){
	if($department['dep_id']==$dep_id){
		echo "<h2>{$department['alias']}</h2>";
		echo '<ol>';
		foreach ($staffs as $staff) {
			if($department['dep_id']==$staff['department']){
				echo "<li><a href='detail.php?id=".$staff['id']."'>{$staff['name']}</a></li>";
			}
		}
		echo '</ol>';
	};
}

include __DIR__.'/public/include/footer.php';
 ?>

detail.php//员工详情页模板

<?php 
include __DIR__.'/public/include/header.php';
$id = $_GET['id'];
foreach ($staffs as $staff) {
	if($staff['id']==$id){
	echo "<h3>{$staff['name']}</h3>";
	echo '<img src="public/static/images/'.$staff['image'].'" width="300px">';
	echo "<p>{$staff['detail']}</p>";	
	}
	
}

include __DIR__.'/public/include/footer.php';

 ?>

--------------

效果图

---------------

首页(全部信息)

QQ截图20190417193735.jpg

部门员工列表页

QQ截图20190417193724.jpg

员工信息详情页

QQ截图20190417193706.jpg

思路:

1、主要是要在a链接中设置好跳转地址和参数,跳转到模板页面时,以$_GET获取传入的参数, 再运用判断语句+循环,匹配满足条件的数据。

2、要做好重复代码部分的分离,实现代码复用




Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post