Blogger Information
Blog 63
fans 1
comment 0
visits 76082
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
制作一个商品的列表与详情模板
桃儿的博客
Original
1688 people have browsed it

 制作一个商品的列表与详情模板

首页:

首页.jpg

栏目页:

栏目页.jpg

详情页:

详情页.jpg

index.php文件

实例

<?php
// 加载公共头部
include __DIR__ . "/inc/header.php";

foreach ($cates as $cate) {
    echo "<h2>{$cate['alias']}</h2>";
    echo '<ol>';
    foreach ($foods as $food) {
        // 判断当前所属栏目是否与当前栏目id相同?
        if ($cate['cate_id'] === $food['cate_id']) {
            echo "<li><a href='detail.php?mov_id=" .$food['food_id']. "'>{$food['name']}</a></li>";
        }
    }
    echo '</ol>';
}

// 加载公共底部
include __DIR__ . '/inc/footer.php';

运行实例 »

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

list.php文件

实例

<?php
// 加载公共头部
include __DIR__ . '/inc/header.php';

$cate_id = $_GET['cate_id'];

// 注意: url中的内容都是字符串, 转换类型
$cate_id = (int)$cate_id;

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

// 加载公共底部
include __DIR__ . '/inc/footer.php';

运行实例 »

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

detail.php文件

实例

<?php
// 加载公共头部
include __DIR__ . '/inc/header.php';

$food_id = intval($_GET['food_id']);


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

// 加载公共底部
include __DIR__ . '/inc/footer.php';

运行实例 »

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


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