Blogger Information
Blog 21
fans 0
comment 0
visits 20360
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
私人影院模板
电动机的博客
Original
3694 people have browsed it

总结:
1、用索引一维数组的循环的显示栏目,用二维数据来显示与栏目对应的影片明细

2、用关联一维数组循环的显示栏目并与key来定义跳转对应栏目的影片明细

3、用二个关联数组通过ID关联,并且用双重循环来组装成模板,

实例

// 栏目数组
$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="public/static/css/style.css">
    <meta name="description" content="<?= $system['desc'] ?>">
    <meta name="keywords" content="<?=$system['key'] ?>">
    <title><?=$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']; ?>">
                    <?=$cate['alias'] ?></a>
            </li>
        <?php endforeach; ?>
    </ul>
</div>

运行实例 »

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

实例

<!--底部版权-->
<div class="footer">
    <p class="copyright"><?=$system['copy']; ?>© 版权所有</p>
</div>
</body>
</html>

运行实例 »

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

实例

.header {
    background-color: brown;
    height: 30px;
}

.nav li {
    list-style:none;
    min-width:80px;
    line-height: 30px;
    float: left;
}

.nav li a {
    text-decoration: none;
    color: white;
}
.nav {
    overflow: hidden;
}
.footer {
    height: 30px;
    background-color: #636363;
    color: white;
    text-align: center;
    line-height: 30px;
}

运行实例 »

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

实例

<?php

include __DIR__ ."/public/include/header.php";

foreach ($cates as $cate) {
echo "<h2>{$cate['alias']}</h2>";
echo '<ol>';
    foreach ($movies as $movie) {
    if ($cate['cate_id'] === $movie['cate_id']) {
    echo "<li><a href='detail.php?mov_id=" .$movie['mov_id']. "'>{$movie['name']}</a></li>";
    }
    }
    echo '</ol>';
}

include __DIR__ . '/public/include/footer.php';

运行实例 »

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

实例

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

$cate_id = $_GET['cate_id'];

foreach ($cates as $cate) {


    if ($cate['cate_id'] == $cate_id) {
        echo "<h2>{$cate['alias']}</h2>";
        echo '<ol>';
        foreach ($movies as $movie) {
            if ($cate['cate_id'] == $movie['cate_id']) {
                echo "<li><a href='detail.php?mov_id=" .$movie['mov_id']. "'>{$movie['name']}</a></li>";
            }
        }
        echo '</ol>';
    };
    }

include __DIR__ . '/public/include/footer.php';

运行实例 »

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

实例

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

$mov_id = $_GET['mov_id'];

// 复制list.php模板直接修改

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

include __DIR__ . '/public/include/footer.php';

运行实例 »

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

 

Correction status:Uncorrected

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