首先看数据表:
index.PHP 入口文件
<?PHP
include "StudentController.PHP";
StudentController.PHP 控制器
<?PHP
require_once ("StudentModel.class.PHP");
$modelObj = new StudentModel();
$arrs=$modelObj->fetchAll();
include "StudentView.html";
StudentModel.class.PHP 模型
<?PHP
class StudentModel{
//获取多行数据
public function fetchAll(){
$db=MysqLi_connect("localhost","root","root","myschool");
//构建查询的sql语句
$sql = "select * from students";
$result=$db->query($sql);
while($row=MysqLi_fetch_all($result,3)){
$rows=$row;
}
return $rows;
}
}
StudentView.html 视图
<!doctype html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<Meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<Meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div align="center">
<h2>显示学生的MVC</h2>
/*前端css显示自己看着办*/
<table width="600" border="1" bordercolor="#ccc" rules="all">
<tr style="
<td>编号</td><td>姓名</td><td>性别</td><td>年龄</td>
</tr>
<?PHP foreach($arrs as $arr){ ?>
<tr>
<td><?PHP echo $arr["stuid"]; ?></td>
<td><?PHP echo $arr["stuname"]; ?></td>
<td><?PHP echo $arr["stusex"]; ?></td>
<td><?PHP echo $arr["age"]; ?></td>
</tr>
<?PHP } ?>
</table>
</div>
</body>
</html>
最后,翠花,上酸菜:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。