我正在一個PHP項目,我試圖將多維數組導出到Smarty。多維數組與smarty
下面是我的陣列的填充方式:
$array = array();
while ($myrow = mysql_fetch_array($result))
{
$array[$myrow['BugID']][$myrow['id']]['BugID'] = $myrow['BugID'];
$array[$myrow['BugID']][$myrow['id']]['DateSent'] = $myrow['DateSent'];
$array[$myrow['BugID']][$myrow['id']]['FromAddress'] = $encryption->decrypt($myrow['FromAddress']);
$array[$myrow['BugID']][$myrow['id']]['ToAddress'] = $encryption->decrypt($myrow['ToAddresss']);
$array[$myrow['BugID']][$myrow['id']]['Message'] = $encryption->decrypt($myrow['Message']);
}
$smarty->assign("array", $array);
$content = $smarty->fetch("message-list.tpl");
下面是我的模板文件
<table class="tableDetails">
<tr>
<th>Date Sent</th>
<th>Bug ID</th>
<th>From Address</th>
<th>To Address</th>
<th>Message</th>
</tr>
{foreach from=$array key=header item=table}
<tr>
<td>{$array.DateSent}</td>
<td>{$array.DateSent}</td>
<td>{$array.DateSent}</td>
<td>{$array.DateSent}</td>
<td>{$array.DateSent}</td>
</tr>
{/foreach}
</table>
Array
(
[2] => Array
(
[3] => Array
(
[BugID] => 2
[DateSent] => 2014-03-17 22:51:08
[FromAddress] => [email protected]
[ToAddress] =>
[Message] => This is a test.
)
)
[1] => Array
(
[2] => Array
(
[BugID] => 1
[DateSent] => 2014-03-15 00:04:03
[FromAddress] => [email protected]
[ToAddress] =>
[Message] => This is a message from the bug administrator to the bug reporter
)
[1] => Array
(
[BugID] => 1
[DateSent] => 2014-03-15 00:03:17
[FromAddress] => [email protected]
[ToAddress] =>
[Message] => This is the content of the message from the bug reporter to the administrator
)
)
)
目前沒有在我的表被輸出,除了表頭,從一無所有實際的數組。
感謝您提供的任何幫助。
請閱讀智者的foreach是如何工作的:http://www.smarty.net/docs/en/language.function.foreach.tpl – Borgtex