Blogger Information
Blog 21
fans 0
comment 0
visits 20129
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数据库代替二维数组
电动机的博客
Original
802 people have browsed it

总结:

1、把数据分别放在一个数据库的三张表中,

2、用三个查询语句把数据赋给三个数组中;

3、利用模板制作网站

实例

<?php

require 'connect.php';



$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="public/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>

运行实例 »

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!