思路:
1.在header.php里新增一个数组$arr_user,存放评论相关的数据。
实例
$arr_user = [['name' => 'wangdage', 'tximg' => 'static/images/tx1.jpg', 'time' => '2019-9-20 20:20:21', 'pl' => '真***', 'dz' => 102, 'hf'=>2, 'mov_id' => 1], ['name' => 'wangdage22', 'tximg' => 'static/images/tx2.jpg', 'time' => '2019-9-22 20:20:21', 'pl' => '真***。', 'dz' => 15, 'hf'=>12, 'mov_id' => 3], ['name' => 'xiaomei', 'tximg' => 'static/images/tx3.jpg', 'time' => '2019-9-22 20:15:21', 'pl' => '最喜欢张无忌了。', 'dz' => 55, 'hf'=>21, 'mov_id' => 1], ['name' => 'whz', 'tximg' => 'static/images/tx4.jpg', 'time' => '2019-9-23 20:20:21', 'pl' => '我喜欢赵敏。', 'dz' => 201, 'hf'=>53, 'mov_id' => 1], ['name' => '蓝色妖姬', 'tximg' => 'static/images/tx5.jpg', 'time' => '2019-9-15 8:20:21', 'pl' => '不怎么***。', 'dz' => 143, 'hf'=>26, 'mov_id' => 8], ['name' => '红***', 'tximg' => 'static/images/tx6.jpg', 'time' => '2019-9-15 8:20:21', 'pl' => '还行吧。', 'dz' => 143, 'hf'=>26, 'mov_id' => 6], ['name' => '找不到回家的路', 'tximg' => 'static/images/tx7.jpg', 'time' => '2019-9-15 8:20:21', 'pl' => '还行吧。', 'dz' => 13, 'hf'=>16, 'mov_id' => 2], ['name' => '采姑娘的小蘑菇', 'tximg' => 'static/images/tx8.jpg', 'time' => '2019-9-15 8:65:24', 'pl' => '还行吧。', 'dz' => 1, 'hf'=>6, 'mov_id' => 3] ]
运行实例 »
点击 "运行实例" 按钮查看在线实例
2.新建一个公用的pl.php文件,存放评论部分的代码,供影视详情页面detail.php引用。
实例
<div class="pl"> <h3>最新评论:</h3> <?php $mov_id = intval($_GET['mov_id']); foreach ($arr_user as $v) if ($mov_id === $v['mov_id']) { echo '<img class="img" src="' . $v['tximg'] . '">'; echo '<div class="user">'; echo '<span>' . $v['name'] . '</span><br>'; echo '<span class="time">' . $v['time'] . '</span></div>'; echo '<p class="pp" >'.$v['pl'].'</p>'; echo '<div class="dzhf"><div><img class="dz" src="static/images/点赞.png"><span>'.$v['dz'].'</span></div>'; echo '<div><img class="hf" src="static/images/回复.png"><span>'.$v['hf'].'</span></div></div>'; }; ?> </div>
运行实例 »
点击 "运行实例" 按钮查看在线实例
3.在pl.php里判断$_GET['mov_id']与数组$arr_user里的'mov_id'是否相等,来加载出相关的评论记录。
4.效果图: