Blogger Information
Blog 19
fans 0
comment 0
visits 8742
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
影视示例详情页面,增加评论展示功能——2019年09月20日23时23分
Song的博客
Original
603 people have browsed it

一、结合已经创建好的影视示例网页,创建一个命名为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资源

include __DIR__ .'/pl.php';

运行实例 »

点击 "运行实例" 按钮查看在线实例

实际效果展示

1.png

总结

将头部,底部等公共部分分割成独立的php文件,使用时引入。用数组替换HTML中的数据内容,用foreach来遍历数组,将所需要的内容输出出来,有效的实现HTML中代码的简化。

Correction status:qualified

Teacher's comments:写得很规范
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