Blogger Information
Blog 10
fans 0
comment 0
visits 8515
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
用php循环输出员工信息表2 2019-03-19
JuJo的博客
Original
777 people have browsed it

实例

<?php
	$a = [
		['id' => 1,'name' => 'jack','age' =>25,'sex' => 1,'emall' => 'fajf@qq.com','password' => 'dfwe123'],
		['id' => 2,'name' => 'rose','age' =>22,'sex' => 0,'emall' => 'rafe@qq.com','password' => '321e123'],
		['id' => 3,'name' => 'davee','age' =>30,'sex' => 1,'emall' => 'derm@qq.com','password' => 'df43s23'],
		['id' => 4,'name' => 'tosi','age' =>36,'sex' => 1,'emall' => 'htdh@qq.com','password' => 'rsft423'],
		['id' => 5,'name' => 'maray','age' =>28,'sex' =>0,'emall' => 'aded@qq.com','password' => '2dgt5e3']
	];
	
	$total = count($a);

	$title = '员工信息表';

	$caption = $title;

?>

<!DOCTYPE html>
<head>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo $title; ?></title>
    <style>
        table,th,td {
            border: 1px solid #666;
            padding: 8px;
        }
        table {
            border-collapse: collapse;
            width: 80%;
            text-align: center;
            margin: 30px auto;
        }
        thead tr:first-of-type {
            background-color: lightblue;
        }
        tbody tr:hover {
            background-color: #efefef;
        }
        table > caption {
            font-size: 1.2rem;
            margin-bottom: 15px;
        }
        table + p {
            text-align: center;
        }
    </style>
</head>
<body>
	<table>
	    <caption>
	        <?php echo $caption; ?>
	    </caption>
	    <thead>
		    <tr>
		        <th>编号</th>
		        <th>姓名</th>
		        <th>年龄</th>
		        <th>性别</th>
		        <th>邮箱</th>
		        <th>密码</th>
		    </tr>
	    </thead>
	    <tbody>
		    <?php
		       $stu = '';
		       foreach ($a as $b){
			       $stu .= "<tr>";
			       $stu .= "<td>{$b['id']}</td>";
			       $stu .= "<td>{$b['name']}</td>";
			       $stu .= "<td>{$b['age']}</td>";
			       $stu .= "<td>".($b['sex'] ? '男' : '女')."</td>";
			       $stu .= "<td>{$b['emall']}</td>";
			       $stu .= "<td>{$b['password']}</td>";
			       $stu .= "</tr>";
		       };
		       echo $stu;
		    ?>



	    </tbody>
</table>
<p>总计:
   <?php echo $total; ?>
   人
 </p>

</body>
</html>>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

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