Correction status:qualified
Teacher's comments:
使用php foreach/if替代语法循环遍历二维数组,生成表格,以及用函数生成表格
实例
<?php $title1="注册用户列表"; $user=[['id'=>1,'name'=>'ch','psw'=>sha1("123456"),'sex'=>1], ['id'=>2,'name'=>'aa','psw'=>md5("111111"),'sex'=>1], ['id'=>3,'name'=>'bb','psw'=>"222222",'sex'=>"0"], ['id'=>4,'name'=>'cc','psw'=>"333333",'sex'=>"1"]]; // 创建函数: 动态生成员工表格 // 函数参数: 表格数据(数组) function createTable($list) { $result = ''; foreach ($list as $value) { $result .= '<tr><td>'.$value["id"].'</td> <td>'.$value["name"].'</td> <td>'.$value["psw"].'</td> <td>'.($value["sex"]?'男':'女').'</td></tr>'; //注意括号 } return $result; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title><?=$title1?></title> </head> <body> <table border="1"> <caption><?=$title1?></caption> <thead> <tr> <th>用户id</th> <th>用户名</th> <th>密码</th> <th>性别</th> </tr> </thead> <tbody> <?php foreach($user as $value):?> <tr> <td><?php echo $value["id"];?></td> <td><?php echo $value["name"];?></td> <td><?=$value["psw"]?></td> <td><?php echo $value["sex"]? '男':'女';?></td> <!-- <td> <?php //if ($value["sex"]==1):?>男 <?php //else:?>女 <?php //endif;?> </td> --> </tr> <?php endforeach;?> <?php echo createTable($user) ;?> </tbody> <tfoot><tr><td colspan=4>总计:<?=count($user)?>人</td></tr></tfoot> </table> <!-- foreach(): endforeach;三元表达式 ? : ;sha1() mad5()加密函数的使用 --> </body> </html>
点击 "运行实例" 按钮查看在线实例
员工管理系统 后台首页
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="layui/css/layui.css"> </head> <body class="layui-layout-body"> <div class="layui-layout layui-layout-admin"> <div class="layui-header"> <div class="layui-logo">员工管理系统</div> <ul class="layui-nav layui-layout-right"> <li class="layui-nav-item">admin【系统管理员】</li> <li class="layui-nav-item"><a href="javascript:;" onclick="logout()">退出</a></li> </ul> </div> <div class="layui-side layui-bg-black"> <div class="layui-side-scroll"> <!-- 左侧导航区域 --> <ul class="layui-nav layui-nav-tree" lay-filter="test"> <li class="layui-nav-item layui-nav-itemed"> <a class="" href="javascript:;">员工管理</a> <dl class="layui-nav-child"> <dd><a href="用户注册表.php" target="mainlist">员工列表</a></dd> </dl> </li> <li class="layui-nav-item"> <a href="javascript:;">权限管理</a> <dl class="layui-nav-child"> <dd><a href="layui_admin.html" target="mainlist">菜单管理</a></dd> <dd><a href="javascript:;">角色管理</a></dd> </dl> </li> </ul> </div> </div> <!-- 内容主体区域 --> <div class="layui-body"> <div style="padding:10px;"> <iframe src="" onload="resetMainHeight(this)" frameborder="0" class="layuiadmin-iframe" width="100%" height="100%" scrolling="no" name="mainlist"></iframe> </div> </div> </div> <script src="layui/layui.js"></script> <script> layui.use(['element','layer'], function(){ var element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块 layer=layui.layer; $=layui.jquery }); function logout(){ layer.confirm('确定要退出吗?', { icon:3, btn: ['确定', '取消'] //可以无限个按钮 }, function(index,layero){//按钮【按钮一】的回调 layer.close(index) }, function(index){ }); } // 设置主操作页面高度 function resetMainHeight(obj){ var height = parent.document.documentElement.clientHeight-53; $(obj).parent('div').height(height) } </script> </body> </html>
点击 "运行实例" 按钮查看在线实例