亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

格式化輸出數(shù)據(jù)表中數(shù)據(jù)

Original 2019-08-12 17:16:49 420
abstract:<?php header("content-type:text/html;charset=utf-8"); //1.創(chuàng)建PDO對象,連接數(shù)據(jù)庫 $pdo=new PDO("mysql:host=127.0.0.1;dbname=php_edu;charset=utf8","root","root")
<?php
header("content-type:text/html;charset=utf-8");


//1.創(chuàng)建PDO對象,連接數(shù)據(jù)庫
$pdo=new PDO("mysql:host=127.0.0.1;dbname=php_edu;charset=utf8","root","root");
//2.創(chuàng)建預(yù)處理對象stmt
$sql = "SELECT `user_id`,`name`,`sex`,`age` FROM `staff`";
$stmt=$pdo->prepare($sql);

//3.執(zhí)行
$stmt->execute();

//4.遍歷結(jié)果
$rows=[];
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $rows[]=$row;
}

//釋放結(jié)果集
$stmt=null;
//關(guān)閉連接
$pdo=null;
//print_r($rows);

?>
<style>
    table,th,td{
        border:1px solid #666;
    }
    table{
        text-align:center;
        border:1px solid #333;
        width:50%;
        margin:30px auto;
        border-collapse: collapse;
    }
    table caption{
        font-size:1.5em;
        font-weight:bolder;
        margin-botton:15px;
    }
    table tr:first-child{
        background-color:lightblue;
    }
</style>
<table>
    <caption>用戶信息表</caption>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>性別</th>
        <th>年齡</th>
    </tr>
    <?php foreach($rows as $row):?>
    <tr>
        <th><?php echo $row['user_id']?></th>
        <th><?php echo $row['name']?></th>
        <th><?php echo ($row['sex'])==1 ? '男生':'女生'?></th>
        <th><?php echo $row['age']?></th>
    </tr>
    <?php endforeach;?>
</table>

1.png

Correcting teacher:天蓬老師Correction time:2019-08-15 10:55:24
Teacher's summary:你的參數(shù)綁定呢, SQL中沒有看到參數(shù), 參數(shù)可以是查詢條件中的變量

Release Notes

Popular Entries