im Smarty newbee。データベースから一部のデータを表示しようとしましたが、ブラウザのページに何も表示されません。私はPHPファイルでクエリを表示しようとしたが、すべて正常に動作しますが、私はSmartyで表示できません。ここに私のコード: New.phpDBからのデータを表示、スマート
<?php
include 'Smarty/libs/Smarty.class.php';
$link = mysqli_connect ('localhost','xxxx','xxxx','xxxx');
$sql = "SELECT * FROM `s_news`";
$result = mysqli_query($link,$sql);
while($row = mysqli_fetch_assoc($result)) {
$data[] = $row; # $data is the array created for use in the Smarty template.
$smarty->assign('data', $data);
$smarty->display('text.tpl');
}
?>
Text.tplファイル:
{foreach from=$cat1 item=item}
<table cellpadding="2" cellspacing="0">
<tr>
<td>Username:</td>
</tr>
{foreach from=$data item=item key=key}
<tr>
<td>{$item.date}</td>
<tr>
{/foreach}
</table>
{/foreach}
ありがとう!
ループ外に割り当てる必要があります。 –
@ YourCommonSense pls answer。私はあなたが言ったことを想像することはできません。 –