Correction status:qualified
Teacher's comments:写得不错, 再有一张图就好了
data:数据页面
head.php:头部页面
index:主页面
list:分类页面
details:详情页面
foot.php:页尾页面
data.php
<?php $db = [ 'type' => 'mysql', 'host' => 'localhost', 'dbname' => 'php', 'username' => 'root', 'password' => 'root', ]; $dsn = "{$db['type']}:host={$db['host']};dbname={$db['dbname']}"; try { $pdo = new PDO($dsn, $db['username'], $db['password']); $sql_category = 'SELECT * FROM category'; $stmt_category = $pdo->prepare($sql_category); $cates = $stmt_category->fetchAll(PDO::FETCH_ASSOC); $stmt_category -> execute(); $sql_talk = 'SELECT * FROM talk '; $stmt_talk = $pdo->prepare($sql_talk ); $talks= $stmt_talk ->fetchAll(PDO::FETCH_ASSOC); $stmt_category -> execute(); $stmt_talk = 'SELECT * FROM movies '; $stmt_movie = $pdo->prepare($sql_movie ); $movies = $stmt_movie ->fetchAll(PDO::FETCH_ASSOC); $stmt_movie -> execute(); } catch (PDOException $e) { die('Connection Failed: ' . $e->getMessage()); } ?>
点击 "运行实例" 按钮查看在线实例
head.php
<?php require_once 'static/inc/data.php'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="static/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?cID=<?php echo $cate['cate_id']; ?>"> <?php echo $cate['alias'] ?> </a> </li> <?php } ?> </ul> </div>
点击 "运行实例" 按钮查看在线实例
index.php
<?php require_once 'static/inc/data.php'; Require_once 'static/inc/head.php'; ?> <div class="mainArea"> <?php foreach ($cates as $cateKey => $cateValue) { echo "<div class='area'><a href='list.php?cID=".$cateValue['cate_id']."'><h2>" . $cateValue['alias'] . "</h2></a></div>"; echo "<ul>"; foreach ($movies as $movieValue) { if($cateValue['cate_id']==$movieValue['cate_id']) { echo '<li>'; echo "<a href='details.php?mID=" . $movieValue['cate_id'] . "'><img src='static/images/" . $movieValue['image'] . "' alt='" . $movieValue['name'] . "'></a><br>" . $movieValue['name'] ; echo '</li>'; } } echo '</ul>'; } ?><br><br><br> <?php require_once 'static/inc/foot.php'; ?>
点击 "运行实例" 按钮查看在线实例
list:分类页
<?php require_once 'static/inc/data.php'; Require_once 'static/inc/head.php'; ?> <div class="mainArea"> <ul> <?php $cateID=$_GET['cID']; foreach ($cates as $cate) { if($cate['cate_id']==$cateID) { echo "<div class='area'><h2>" . $cate['alias'] . "</h2></div>"; $cateID=$cate['cate_id']; foreach ($movies as $movie) { if($movie['cate_id']==$cateID) { echo '<li>'; echo "<a href='details.php?mID=" . $movie['cate_id'] . "'><img src='static/images/" . $movie['image'] . "' alt='" . $movie['name'] . "'></a><br>" . $movie['name'] ; echo '</li>'; } } break; } } ?> </ul> </div> <?php require_once 'static/inc/foot.php'; ?>
点击 "运行实例" 按钮查看在线实例
details:详情页
<?php require_once 'static/inc/data.php'; Require_once 'static/inc/head.php'; ?> <div class="mainArea"> <ul> <?php $mID=$_GET['mID']; foreach ($movies as $movie) { if($movie['mov_id']==$mID) { echo '<li>'; echo $movie['name'] . "<br><img src='static/images/" . $movie['image'] . "' alt='" . $movie['name'] . "'><br>" ; echo '<hr>'; foreach ($talks as $talk) { if($talk['mov_id']==$movie['mov_id']) { echo "<br><span class='talkList'>" . $talk['talk_time'] . "<br>" . $talk['talk_info'] . "</span>"; } } echo '</li>'; } } ?> </ul> </div> <?php require_once 'static/inc/foot.php'; ?>
点击 "运行实例" 按钮查看在线实例
foot.php
<div class="footer"> <p class="copyright">欧阳克 © 版权所有</p> </div> </body> </html>
点击 "运行实例" 按钮查看在线实例