abstract:<!--繼承--> {extends file="layout.html"} {block name="content"} {*引入父類文件*} {$smarty.block.parent} <style> table {  
<!--繼承--> {extends file="layout.html"} {block name="content"} {*引入父類文件*} {$smarty.block.parent} <style> table { margin:0 auto; width:1200px; text-align: center; border:1px solid #999; } table th { background-color:#f0ffff; } table td { border:1px solid #999; } </style> <table > <tr> <th>編號(hào)</th> <th>導(dǎo)演姓名</th> <th>電話</th> <th>演員名字</th> <th>播放量</th> <th>配合演員</th> <th>主演身高</th> </tr> {foreach $name as $row} <tr> <td>{$row['id']}</td> <td>{$row['director']}</td> <td>{$row['filmTime']}</td> <td>{$row['filmActor']}</td> <td>{$row['playNum']}</td> <td>{$row['actorName']}</td> <td>{$row['actorHeight']}</td> </tr> {/foreach} </table> {/block}
<?php require __DIR__.'/config/config.php'; // 使用 mysqli鏈接數(shù)據(jù)庫(kù) $db = @mysqli_connect('127.0.0.1','root','root','phpcn','3306'); if(!$db){ exit(mysqli_connect_error()); } $res = mysqli_query($db,"select * from `film`"); $rows = []; while($row = mysqli_fetch_assoc($res)){ $rows[] = $row; } $smarty->assign('name',$rows); //渲染一定要寫在變量后面,這樣才能引入到變量 $smarty->display("zuoye.html"); //關(guān)閉數(shù)據(jù)庫(kù) mysqli_close($db); ?>
Correcting teacher:韋小寶Correction time:2019-03-05 09:14:08
Teacher's summary:Smarty模板引擎在很多框架中都在使用 學(xué)習(xí)好了Smarty模板引擎中的語(yǔ)法 以后在使用框架寫項(xiàng)目的時(shí)候渲染模板將會(huì)變的很簡(jiǎn)單