Blogger Information
Blog 38
fans 0
comment 3
visits 43955
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP基础-数据存入表格
意外的博客
Original
1005 people have browsed it
<?php
header('Content-type: text/html; charset=utf-8'); 

$arr = array(
            array( 1, '王大大', 30, 1, 123456),
            array( 2, '张三', 18, 2, 123456),
            array( 3, '李四',16, 1, 123456),
            array( 4, '欧阳克',20, 2, 123456),
            );
//求数量;
$like=count($arr);

//定义一个标题的名称
$title='大人物';

function createtable($arr){
$str= '';
//将这个数组进行循环;
foreach ($arr as  $value) {
    $str .= '<tr>';
        $str .= '<td>' . $value['0'] . '</td>';
        $str .= '<td>' . $value['1'] . '</td>';
        $str .= '<td>' . $value['2'] . '</td>';
        $str .= '<td>' . ($value['3']==1?'男':'女') . '</td>';
        $str .= '<td>' . $value['4'] . '</td>';
        $str .= '</tr>';
}

//将结果$str返回(给createtable函数;)
return $str;
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>php3月19直播作业</title>
  <style type="text/css">
  *{margin: 0;padding: 0;}

th,td{
border:1px solid blue;
padding: 8px;
}
table{
width: 60%;
margin: 30px auto;
text-align: center; /*文字居中;*/
border-collapse: collapse;
}
th{
background:red;
}
p {
/*margin-top: 20px;*/
       text-align: center;
    }
  h2{
  margin-top: 120px;
  text-align: center;
  }
</style>
</head>
<body>
<table>
<h2><?php echo $title;?></h2>
    <tr>
       <th>编号</th>
       <th>姓名</th>
       <th>年龄</th>
       <th>性别</th>
       <th>密码</th>
    </tr>
  <?php echo createtable($arr); ?>
</table>
<p>总人数: <?php echo $like;?>人</p>
  

</body>
</html>

总结;

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