本章节总结与练习

原创 2019-01-16 16:41:06 283
摘要:<meta charset="UTF-8"> <?php require __DIR__.'/config/config.php'; //使用pdo连接数据库 $type = 'mysql'; $host = '127.0.0.1'; $dbname&
<meta charset="UTF-8">
<?php

require __DIR__.'/config/config.php';
//使用pdo连接数据库
$type = 'mysql';
$host = '127.0.0.1';
$dbname = 'mysqllearn';
$dsn = "$type:host=$host;dbname=$dbname;";
$user = 'root';
$pass = 'root';
$pdo = new PDO($dsn,$user,$pass);
//var_dump($pdo);
//sql语句
$sql = "SELECT * FROM `filming`";
//预处理
$stmt = $pdo->prepare($sql);
//执行
$stmt->execute();
//取出值赋给数组
$arr = [];
$arr = $stmt->fetchAll(PDO::FETCH_ASSOC);
//模板赋值
$smarty->assign('arr',$arr);
//渲染
$smarty->display(__DIR__.'/temp/index.html');
?>
{*公共头部*}
{include file="public/head.html"}

<style type="text/css">
    .abctable{ width: 500px; height: 200px;}
</style>
<table class="abctable" border="1" align="center">
    <tr class="abctable-tr">
        <th>影片ID</th>
        <th>影片名</th>
        <th>影片上映时间</th>
        <th>影片类型</th>
    </tr>
    {foreach $arr as $v}
    <tr>
        <th>{$v.v_id}</th>
        <th>{$v.v_name}</th>
        <th>{$v.v_release}</th>
        <th>{$v.v_type}</th>
    </tr>
    {/foreach}
</table>


{*公共尾部*}
{include file="public/tails.html"}

公共头部

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表格</title>
</head>
<body>
</body>
</html>

1.jpg

2.jpg

批改老师:天蓬老师批改时间:2019-01-16 16:48:12
老师总结:作业写得不错, 就是表格有点丑, 哈

发布手记

热门词条