格式化输出数据表中的数据

Original 2019-04-12 16:11:55 177
abstract:<?php /**  * Created by PhpStorm.  * User: hp  * Date: 2019/4/12  * Time: 15:29  */ require 'text1.php'; $sql 
<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2019/4/12
 * Time: 15:29
 */
require 'text1.php';
$sql = "SELECT `user_id`,`name`,`email`,`create_time`,`age` FROM `user` WHERE `user_id` > :user_id ;";
$stmt = $pdo->prepare($sql);
$stmt->execute([':user_id'=>2]);
$rows = [];
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
    $rows[] = $row;
}
$stmt = null;

$pdo = null;
?>
<style>
    table,th,td {
        border: 1px solid #333;
    }
    table {
        text-align: center;
        border: 1px solid #333;
        width: 50%;
        margin: 30px auto;
        border-collapse: collapse;
        box-shadow: 10px 10px 5px #888888;
    }
    table caption {
        font-size: 1.5em;
        font-weight: bold;
        margin-bottom: 15px;
    }
    table tr:first-child {
        background-color: chartreuse;
    }
</style>
<table>
    <caption style="box-shadow: 10px 10px 5px #888888;">用户信息表</caption>
    <tr>
        <th style="color: red">ID</th>
        <th>姓名</th>
        <th>邮箱</th>
        <th>注册时间</th>
        <th>年龄</th>
    </tr>
    <?php foreach ($rows as $row) :?>
        <tr>
            <td><?php echo $row['user_id'] ?></td>
            <td><?php echo $row['name'] ?></td>
            <td><?php echo $row['email'] ?></td>
            <td><?php echo date('Y/m/d',$row['create_time']) ?></td>
            <td><?php echo $row['age'] ?></td>
        </tr>
    <?php endforeach;?>
</table>

效果图如下:

XMT)NS)5){6LBL@~FLK)S0N.png

Correcting teacher:天蓬老师Correction time:2019-04-12 17:00:27
Teacher's summary:代码写得非常的工整,看上去非常的舒服 模板输出也非常的优雅, 使用了替代标签, 干 掉了大括号, 让html与php代码一目了然, 不错

Release Notes

Popular Entries