Blogger Information
Blog 42
fans 0
comment 0
visits 36368
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
影视详情页面增加评论展示功能20190919作业
庆选的博客
Original
708 people have browsed it

总结:实现原理,在原来heard.php中数据基础增加评论数组comment (数组变成三维数字)。

1、根据mov_id将评论数组comment定位。即是根据电影对应id获取对应的评论数组。

2、将对应数组的内容轮寻出来,并将数据在前端展示

header.php

实例

<?php
	// 影视剧数组
	$movies = [
		[
			'mov_id'=>1,
			'name'=>'倚天屠龙记',
			'image'=>'1.jpg',
			'detail'=>'元朝末年,群雄纷起,武林动荡。江湖传闻,得到屠龙刀倚天剑者,可以成为武林至尊,号令天下,莫敢不从。一时间风云四起,引发了武林中对屠龙刀倚天剑的争夺,几段姻缘和孽缘也由此产生。武当派张翠山与天鹰教殷素素…	',
			'cate_id'=>1,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'倚天屠龙记,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'倚天屠龙记,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'倚天屠龙记,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'倚天屠龙记,给心'
				           ],
				            [
				           'comment_id'=>5,
				           'comment_neme'=>'周五',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'倚天屠龙记,给心5'
				           ],
				            [
				           'comment_id'=>6,
				           'comment_neme'=>'吴六',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'倚天屠龙记,给心5'
				           ],
			           ]
		],
		[
			'mov_id'=>2,
			'name'=>'都挺好',
			'image'=>'2.jpg',
			'detail'=>' 苏母的的突然离世打破了这个家庭外表的平静,意想不到的隐患层层显露,对毫无主见却又自私、小气的苏父的安置和后续生活问题,引发了远在国外的大哥与本城的二哥、小妹三家规律生活的不再。一直被苏母压制的苏父翻…	',
			'cate_id'=>1,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'都挺好,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'都挺好,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'都挺好,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'都挺好,给心'
				           ]
			           ]
		],
		[
			'mov_id'=>3,
			'name'=>'如果可以这样爱',
			'image'=>'3.jpg',
			'detail'=>'一对已婚男女突然徇情自杀,以为可以结束这一切,却不料悲剧才刚刚开始——他们的爱人,耿墨池和白考儿,同时在葬礼上邂逅。面对同样的背叛他们同时选择报复但又同时爱上彼此,注定饱受打击和折磨。然而他们想真心拥…	',
			'cate_id'=>1,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'如果可以这样爱,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'如果可以这样爱,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'如果可以这样爱,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'如果可以这样爱,给心'
				           ]
			           ]
		],
		[
			'mov_id'=>4,
			'name'=>'复仇者联盟4',
			'image'=>'4.jpg',
			'detail'=>'《复仇者联盟4:终局之战》将是漫威宇宙“无限传奇”(The Infinity Saga)的终结篇,是漫威电影宇宙十年的一个重要节点,结束部分英雄电影的故事,但也将展开新的剧情,呈现新的更为广阔宏大的宇…',
			'cate_id'=>2,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'复仇者联盟4,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'复仇者联盟4,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'复仇者联盟4,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'复仇者联盟4,给心'
				           ]
			           ]
		],
		[
			'mov_id'=>5,
			'name'=>'波西米亚狂想曲',
			'image'=>'5.jpg',
			'detail'=>'弗雷迪·默丘里成名前在机场做行李搬运工。有一天,默丘里毛遂自荐加入杰·泰勒与布莱恩·梅的乐团,恰巧当天原本的主唱辞职,默丘里用自己横跨四个八度的超广音域说服两人,从此开启皇后乐团的摇滚传奇!',
			'cate_id'=>2,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'波西米亚狂想曲,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'波西米亚狂想曲,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'波西米亚狂想曲,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'波西米亚狂想曲,给心'
				           ]
			           ]
		],
		[
			'mov_id'=>6,
			'name'=>'阿丽塔:战斗天使',
			'image'=>'6.jpg',
			'detail'=>'弗雷迪·默丘里成名前在机场做行李搬运工。有一天,默丘里毛遂自荐加入杰·泰勒与布莱恩·梅的乐团,恰巧当天原本的主唱辞职,默丘里用自己横跨四个八度的超广音域说服两人,从此开启皇后乐团的摇滚传奇!',
			'cate_id'=>2,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'阿丽塔:战斗天使,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'阿丽塔:战斗天使,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'阿丽塔:战斗天使,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'阿丽塔:战斗天使,给心'
				           ]
			           ]
		],
		[
			'mov_id'=>7,
			'name'=>'情书',
			'image'=>'7.jpg',
			'detail'=>'***神户某个飘雪的冬日,渡边博子(中山美穗)在前未婚夫藤井树的三周年祭日上又一次悲痛到不能自已。正因为无法抑制住对已逝恋人的思念,渡边博子在其中学同学录里发现“藤井树” 在小樽市读书时的地址时,依循着…',
			'cate_id'=> 3,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'情书,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'情书,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'情书,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'情书,给心'
				           ]
			           ]
		],
		[
			'mov_id'=>8,
			'name'=>'天空之城',
			'image'=>'8.jpg',
			'detail'=>'韩书珍将两个女儿的教育问题和对丈夫的贤内助工作都做得井井有条,在天空之城之中也是备受瞩目的女王,但其实书珍一直隐藏着不为人所知的秘密。李秀林是个充满了关怀和情感丰沛的童话作家,在书珍的引导之下成为了天…',
			'cate_id'=>3,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'天空之城,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'天空之城,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'天空之城,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'天空之城,给心'
				           ]
			           ]
		],
		[
			'mov_id'=>9,
			'name'=>'龙猫',
			'image'=>'9.jpg',
			'detail'=>'为了方便妻子草壁靖子养病,草壁达郎决定带着两个女儿草壁皋月和草壁米搬到草壁靖子所在疗养院附近的乡下,父女三人入住了一间年久失修的老房子。小姐妹俩很快发现看似平凡无奇的乡下有很多神奇的事物,无人居住的房…',
			'cate_id'=>3,
			'comment'=>[
				           [
				           'comment_id'=>1,
				           'comment_neme'=>'赵一',
				           'comment_time'=>'2019-01-02',
				           'comment'=>'龙猫,真***'
				           ],
				           [
				           'comment_id'=>2,
				           'comment_neme'=>'钱二',
				           'comment_time'=>'2019-02-02',
				           'comment'=>'龙猫,不错不错'
				           ],
				           [
				           'comment_id'=>3,
				           'comment_neme'=>'孙三',
				           'comment_time'=>'2019-03-02',
				           'comment'=>'龙猫,值得推荐'
				           ],
				           [
				           'comment_id'=>4,
				           'comment_neme'=>'李四',
				           'comment_time'=>'2019-04-02',
				           'comment'=>'龙猫,给心'
				           ]
			           ]
		],
	];

	// 栏目数组
	$cates = [
		['cate_id'=>1, 'name'=>'gc', 'alias'=>'国产好剧'],
		['cate_id'=>2, 'name'=>'om', 'alias'=>'欧美猛片'],
		['cate_id'=>3, 'name'=>'rh', 'alias'=>'日韩新片'],
	];

	// 网站的系统设置
	$system = [
		'sys_id'=>1,
		'title'=>'私人影院',
		'desc'=>'收集全网最新最全的影视资源',
		'key'=>'国产,欧美,日韩',
		'copy'=>'php中文网'
	]
?>

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" href="css/style.css">
		<meta name="description" content="<?php echo $system['desc'] ?>">
		<meta name="keywords" content="<?php echo $system['key'] ?>">
		<title><?php echo $system['title'] ?></title>
	</head>
	<body>
		<!--头部导航-->
		<div class="header">
			<ul class="nav">
				<li><a href="index.php">首页</a></li>
				<?php foreach ($cates as $cate) : ?>
					<li><a href="list.php?cate_id=<?php echo $cate['cate_id']; ?>"><?php echo $cate['alias'] ?></a></li>
				<?php endforeach; ?>
			</ul>
		</div>

运行实例 »

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

detail.php:

实例

<?php 
	include __DIR__ .'/header.php';

	$mov_id = $_GET["mov_id"];
	$mov_id = intval($mov_id);
	


	foreach ($movies as $movie) { 
		 if ($movie['mov_id'] === $mov_id) {
		 	echo "<h2>{$movie['name']}</h2>";
		 	echo "<img width='300' src=images/" .$movie['image'] . ">";
		 	echo "<p style='text-indent: 2em'>{$movie['detail']}</p>";
		 }
	}

	foreach ($movies as $comment) { 
		 if ($comment['mov_id'] === $mov_id) {
		 	echo "关于【".$comment['name']."】评论内容:";
		 	foreach ($comment['comment'] as $v) {
		 		echo "<div style='border: 2px solid red; margin:10px auto;'>";
		 		echo '序号:' .$v['comment_id'].'                    '.'时间:'.$v['comment_time'];
		 		echo "</br>";
		 		echo $v['comment_neme']. ':'.$v['comment'];
		 		echo "</div >";

		 	}
		 	
		 }
	}

	include __DIR__ .'/footer.php';

?>

运行实例 »

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

效果图:

1.png2.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
Author's latest blog post