[英]Show mysql query using Smarty php
我正在將博客作為學校項目,但是有點卡住了。
該項目的要求之一是使用smarty,這對我來說是全新的。
我的問題是我想將數據庫中的“博客文章”分配給智能變量。 我的方法是這樣的:
<?php
require_once('connect_db.php');
$result = $db->query("SELECT * FROM Innlegg");
while ($row = $result->fetch_assoc())
{print ("<h1>" . $row["forfatter"] . "</h1>");
print ($row["innhold"]);}
?>
現在我只是從“ Innlegg”打印出“ forfatter”。 如何通過使用smarty來完成?
嘗試先閱讀Smarty常見問題解答 。
$list=array();
while ($row = $result->fetch_assoc()) {
$list[]=$row;
}
$smarty = new Smarty(); //maybe some configuration ?
$smarty->assign('list', $list);
$smarty->fetch('index.tpl');
並在smarty index.tpl模板文件中
{foreach from=$list item=row}
<h1>{$row.forfatter}</h1>
{$row.innhold}
{/foreach}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.