批改状态:合格
老师批语:落了不少作业, 完成的还好
运行效果:

评论数组列表:header.php中创建数组comments
$comments = [ ['comment_id'=>1, 'comment_content'=>'这片子不错', 'comment_belonger'=>'张三'], ['comment_id'=>1, 'comment_content'=>'哈哈哈哈哈哈哈哈哈哈哈', 'comment_belonger'=>'李四'], ['comment_id'=>1, 'comment_content'=>'希望翻拍续集', 'comment_belonger'=>'王五'], ['comment_id'=>4, 'comment_content'=>'呵呵', 'comment_belonger'=>'张三'], ['comment_id'=>4, 'comment_content'=>'啊阿阿阿阿阿阿', 'comment_belonger'=>'李四'], ['comment_id'=>4, 'comment_content'=>'嘿嘿嘿嘿', 'comment_belonger'=>'王五'], ];
点击 "运行实例" 按钮查看在线实例
评论列表:在详情页下方加入评论,foreach遍历评论,comment_id和网页跳转的get的mov_id值做匹配,输出对应的 comment_content和comment_belonger
echo "<h3>热门评论</h3>";
foreach($comments as $comment){
if($mov_id==$comment['comment_id']){
echo "<h4>{$comment['comment_belonger']}:</h4>";
echo "{$comment['comment_content']}";
echo '<br>';
echo '<br>';
echo '<br>';
}
};
if(isset($_POST['belonger'])){
echo "<h4>{$_POST['belonger']}</h4>";
}
if(isset($_POST['content'])){
echo $_POST['content'];
}
echo '<br>';
echo '<br>';
echo '<br>';点击 "运行实例" 按钮查看在线实例
增加评论:用post传标签的值到本页面,isset判断是否接受到$_post['']值,点击按钮提交当有值时输出。
echo "<h3>热门评论</h3>";
foreach($comments as $comment){
if($mov_id==$comment['comment_id']){
echo "<h4>{$comment['comment_belonger']}:</h4>";
echo "{$comment['comment_content']}";
echo '<br>';
echo '<br>';
echo '<br>';
}
};
if(isset($_POST['belonger'])){
echo "<h4>{$_POST['belonger']}</h4>";
}
if(isset($_POST['content'])){
echo $_POST['content'];
}
echo '<br>';
echo '<br>';
echo '<br>';点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号