Blogger Information
Blog 4
fans 0
comment 0
visits 3188
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
mvc模式的起步一
不喜欢吃糖的博客
Original
656 people have browsed it

QQ图片20171211144309.png

<?php
 /*
 mvc编程思想
  */
 //获取数据 Model 模型层
 header("Content-type: text/html; charset=utf-8");
 $connect = mysqli_connect('localhost','edu','7uwFtLLfyeRpdPRV','edu') or die('Unale to connect');
 $result = mysqli_query($connect,"SELECT * FROM Student");
 if($result && mysqli_num_rows($result)>0) {
    $rows = mysqli_fetch_all($result,MYSQLI_ASSOC);//$rows是一个二维数组
 }else{
 	echo '<h2>没有返回数据</h2>';
 }

 //显示数据 View 视图层
 echo '<h2 align="center">学生信息表</h2>';
 echo '<table border="1" cellspacing="0" cellpadding="5" align="center" width="60%">';
 echo '<tr align="center" bgcolor="#87eed" ><th>id</th><th>姓名</th><th>邮箱</th><th>课程</th><th>成绩</th></tr>';
 foreach ($rows as $row) {
 	# code...
 	echo '<tr align="center">';
 	echo '<td>'.$row['id'].'</td><td>'.$row['name'].'</td><td>'.$row['email'].'</td><td>'.$row['course'].'</td><td>'.$row['grade'].'</td>';
 	echo '</tr>';
 }
 echo '</table>';

图片是老师的代码,按照老师的敲出来出现报错,注:并不是老师的是错误的,可能是我这边的环境有一些出入,然后自己进行了一些修改。

环境phpstudy2017,mysqli扩展已经开启。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!