Blogger Information
Blog 22
fans 0
comment 0
visits 18362
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
影视详情页面,增加评论展示功能---2019-09-23
sjgbctjda的博客
Original
699 people have browsed it

影视详情页面,增加评论展示功能

实例

<?php 
    $comment=[
        [
            ['id'=>'s123',
            'content'=>'还有点***',
            'time'=>'2019-1-2',
            'mov_id'=>'1'
    ],
        ['id'=>'ssdf123',
        'content'=>'还有点***',
        'time'=>'2019-1-2',
        'mov_id'=>'1'
    ],
        ['id'=>'ssdfasf123',
        'content'=>'还有点***',
        'time'=>'2019-1-2',
        'mov_id'=>'1'
        ]
],
    [
        ['id'=>'swer123',
        'content'=>'还有点***',
        'time'=>'2019-1-2',
        'mov_id'=>'2'
        ],
        ['id'=>'wers123',
        'content'=>'不错',
        'time'=>'2019-1-2',
        'mov_id'=>'2'
        ],
        ['id'=>'s123',
        'content'=>'阔以',
        'time'=>'2019-1-2',
        'mov_id'=>'2'
        ]
]
]
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <meta charset="UTF-8"> 
	</head>
	<body>
        <div class="comment">
        <form action="" method="get" >
        <textarea placeholder="请输入评论" name="comment"></textarea>
        <button onclick="fn()">提交评论</button>
		</form>
        </div>
	</body>
</html>
<!-- <?php
    if(empty($_GET['comment'])){
        echo "<script>alert('请输入评论再提交')</script>";
    }else{
         echo '<div class="pinglun">';
         echo '<span>'.$_GET['comment'].'</span>';
         echo '<span>'.date('Y-m-d h:i:s', time()).'</span>';
         echo '</div>';
    }
    
?> -->
<?php 
    //获取当前电影ID
    $mov_id = $_GET['mov_id'];
    foreach($comment as $v){
        if(is_array($v)){
            foreach($v as $kk=>$vv){
                 // 判断评论的电影是否与当前页面电影匹配
                if( $vv['mov_id']===$mov_id ){
                    echo '<div class="pinglun">';
                    echo '<span>'.$vv['id'].':'.$vv['content'].'</span>';
                    echo '<span>'.$vv['time'].'</span>';
                    echo '</div>';
                    echo '<hr>';
                }
            }    
        }
      
    }
?>

运行实例 »

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

运行结果:

2019-09-23_144615.png

小结:代码只能从数组数据中获取已经存在的数据;不能在上面的文本框中输入然后在下展示。评论点击按钮页面不能再同一页面进行跳转,需要进行下一步改进。


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