Correction status:qualified
Teacher's comments:现在应该知道如何模块化一个站点了吧
首先,网站结构为
要在影视详情页中添加 用户评论,因此数据就暂时先放置在 detail.php 页
detail.php
<?php // 加载公共头部 include __DIR__ . '/header.php'; //评论数据 $comments = [ [ // 评论ID 'com_id' => 1, 'user' => '用户1', 'detail' => '童年回忆', // 视频ID 'mov_id' => 1 ], [ // 评论ID 'com_id' => 2, 'user' => '用户2', 'detail' => '不错不错不错不错不错不错不错不错', // 视频ID 'mov_id' => 1 ], [ // 评论ID 'com_id' => 3, 'user' => '用户3', 'detail' => '观感还行观感还行观感还行观感还行观感还行', // 视频ID 'mov_id' => 2 ], [ // 评论ID 'com_id' => 4, 'user' => '用户4', 'detail' => '差强人意差强人意差强人意差强人意', // 视频ID 'mov_id' => 2 ], [ // 评论ID 'com_id' => 5, 'user' => '用户5', 'detail' => '很好很好很好很好很好很好', // 视频ID 'mov_id' => 3 ], [ // 评论ID 'com_id' => 6, 'user' => '用户6', 'detail' => '令人感动令人感动令人感动令人感动令人感动', // 视频ID 'mov_id' => 3 ], [ // 评论ID 'com_id' => 7, 'user' => '用户7', 'detail' => '勉勉强强吧勉勉强强吧勉勉强强吧勉勉强强吧', // 视频ID 'mov_id' => 4 ], [ // 评论ID 'com_id' => 8, 'user' => '用户8', 'detail' => '退票退票退票退票退票退票退票退票退票', // 视频ID 'mov_id' => 4 ], [ // 评论ID 'com_id' => 9, 'user' => '用户9', 'detail' => '相当不错相当不错相当不错相当不错', // 视频ID 'mov_id' => 5 ], [ // 评论ID 'com_id' => 10, 'user' => '用户10', 'detail' => '凑合看看吧凑合看看吧凑合看看吧凑合看看吧凑合看看吧', // 视频ID 'mov_id' => 5 ], [ // 评论ID 'com_id' => 11, 'user' => '用户11', 'detail' => '挺***的挺***的挺***的挺***的', // 视频ID 'mov_id' => 6 ], [ // 评论ID 'com_id' => 12, 'user' => '用户12', 'detail' => '全程高能惊喜不断全程高能惊喜不断全程高能惊喜不断', // 视频ID 'mov_id' => 6 ], [ // 评论ID 'com_id' => 13, 'user' => '用户13', 'detail' => '睡着了睡着了睡着了睡着了睡着了睡着了', // 视频ID 'mov_id' => 7 ], [ // 评论ID 'com_id' => 14, 'user' => '用户14', 'detail' => '无语无语无语无语无语无语无语', // 视频ID 'mov_id' => 8 ], ]; $mov_id = intval($_GET['mov_id']); // 复制list.php模板直接修改 foreach ($movies as $movie) { if ($movie['mov_id'] === $mov_id) { echo "<h3 class='movie-name'>{$movie['name']}</h3>"; echo '<img class="pic" src="static/images/' . $movie['image'] . '" alt="" width="300">'; echo "<p style='text-indent: 2em' class='detail'>{$movie['detail']}</p>"; } }; echo "<h3>最新评论</h3>"; echo "<ul class='list'>"; foreach ($comments as $item) { if ($item['mov_id'] == $mov_id) { echo '<li class="comment-item"><span class="user">' .$item['user'].'</span>'. $item['detail'] . '</li>'; } } echo "</ul>"; // 加载公共底部 include __DIR__ . '/footer.php';
所得的一些效果图: