Blogger Information
Blog 40
fans 0
comment 0
visits 29545
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
作业--2019-06-06
小人物的博客
Original
1198 people have browsed it

1.将电影网站的内容全部用数据库来进行管理。

实例

<?php
// 连接数据库:$pdo
require 'connect.php';


// 获取网站配置信息(SEO)
$sql = 'SELECT * FROM `system` LIMIT 1';
$stmt = $pdo->prepare($sql);
$stmt->execute();
$system = $stmt->fetch(PDO::FETCH_ASSOC);


// 获取栏目信息
$sql = 'SELECT `cate_id`,`name`,`alias` FROM `category`';
$stmt = $pdo->prepare($sql);
$stmt->execute();
$cates = $stmt->fetchAll(PDO::FETCH_ASSOC);
$cate_count = count($cates);    // 栏目数量


// 获取影视信息
$sql = 'SELECT `mov_id`,`name`,`image`, `detail`, `cate_id` FROM `movies`';
$stmt = $pdo->prepare($sql);
$stmt->execute();
$movies = $stmt->fetchAll(PDO::FETCH_ASSOC);

?>

<!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?cate_id=<?php echo $cate['cate_id']; ?>"><?php echo $cate['alias'] ?></a></li>
        <?php endforeach; ?>
    </ul>
</div>

运行实例 »

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

实例

<?php

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

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

运行实例 »

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

实例

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

$mov_id = $_GET['mov_id'];

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

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

运行实例 »

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

0606-1.png0606-2.png

2.熟悉和掌握cookie和session中常用的函数以及超全局变量的使用

* cookie与session

 * 1. cookie与session是php中非常有效的在多页面间跟踪用户的手段

 * 2. cookie是将用户信息保存在浏览器端,因为浏览器的限制,容量有限,且并不安全

 * 3. session,也叫会话,是将用户信息保存到服务器端,容量更大,并且非常安全

 * 4. 其实session也是基于cookie的,将标识用户身份的SESSION_ID保存在客户端

 * 5. 所以cookie与session密不可分,尽管在操用session时,cookie似乎感觉不到


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