Correction status:qualified
Teacher's comments:写得很规范
一、结合已经创建好的影视示例网页,创建一个命名为pl.php的文件,在文件种创建数组$arr_pl,存放评论里需要展示的数据。
$arr_pl = [ [ 'name' => 'xiaomi1', 'time' => '2019-9-23 23:23:23', 'pl' => '不错', 'mov_id' => 1 ], [ 'name' => 'xiaomi2', 'time' => '2019-9-22 22:22:22', 'pl' => '贼***', 'mov_id' => 1 ], [ 'name' => 'xiaomi3', 'time' => '2019-9-21 21:21:21', 'pl' => '赵敏好漂亮', 'mov_id' => 1 ], [ 'name' => 'xiaomi4', 'time' => '2019-9-20 20:20:20', 'pl' => '我喜欢赵敏', 'mov_id' => 2 ], [ 'name' => 'xiaomi5', 'time' => '2019-9-19 19:19:19', 'pl' => '贼***', 'mov_id' => 3 ], [ 'name' => 'xiaomi6', 'time' => '2019-9-19 18:18:18', 'pl' => '贼***', 'mov_id' => 4 ], [ 'name' => 'xiaomi7', 'time' => '2019-9-17 17:17:17', 'pl' => '贼***', 'mov_id' => 5 ], [ 'name' => 'xiaomi8', 'time' => '2019-9-16 16:16:16', 'pl' => '贼***', 'mov_id' => 6 ], [ 'name' => 'xiaomi9', 'time' => '2019-9-16 16:16:16', 'pl' => '贼***', 'mov_id' => 7 ], [ 'name' => 'xiaomi10', 'time' => '2019-9-16 16:16:16', 'pl' => '贼***', 'mov_id' => 8 ], [ 'name' => 'xiaomi11', 'time' => '2019-9-16 16:16:16', 'pl' => '贼***', 'mov_id' => 9 ], ]
点击 "运行实例" 按钮查看在线实例
二、在pl.php文件编写评论显示循环
<div> <h3>最新评论:</h3> <?php $mov_id = intval($_GET['mov_id']); foreach ($arr_pl as $v) if ($mov_id === $v['mov_id']) { echo '<div>'; echo $v['name']; echo '<br>'; echo $v['time']; echo '<p>'.$v['pl'].'</p>'; }; ?> </div>
点击 "运行实例" 按钮查看在线实例
三、在detail.php中引用pl.php资源
实际效果展示
总结
将头部,底部等公共部分分割成独立的php文件,使用时引入。用数组替换HTML中的数据内容,用foreach来遍历数组,将所需要的内容输出出来,有效的实现HTML中代码的简化。