PHP从数据库获取数据并遍历在表格中php从数据库获取数据并遍历在表格中
<?php
/*连接数据库并以⼀个数组的形式获得数据*/
header("Content-type:text/html;charset=UTF-8");
$con = mysqli_connect('localhost','root','','login');
mysqli_set_charset($con,'utf8');
if(!$con){
die('Could not connect:' . mysql_error($con));
}
$sql = "select * from file";
$result = mysqli_query($con,$sql);
$rows = array();
while($row = mysqli_fetch_assoc($result)){
$rows[] = $row;
}
>
<!DOCTYPE html>
<html lang="en" xmlns="/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>员⼯档案</title>
<link rel="stylesheet" href="style.css" />
</head>
<table>
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>职位</th>
<th>⾝份证号</th>
<th>⾝份证地址</th>
<th>性别</th>
<th>⼊职⽇期</th>
<th>⼿机号</th>
</tr>
</thead>
<tbody>
/*遍历获得的数组*/
<?php foreach($rows as $key => $v) {?>
<tr>
<td><?php echo $v['id'];?></td>
<td><?php echo $v['name'];?></td>
<td><?php echo $v['job'];?></td>
<td><?php echo $v['number'];?></td>
<td><?php echo $v['address'];?></td>
表格网站php源码
<td><?php echo $v['sex'];?></td>
<td><?php echo $v['time'];?></td>
<td><?php echo $v['cell'];?></td>
</tr>
<?php };?>
</tbody>
</table>
</body>
</html>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。