<?php
include "../smarty.inc.php";
$mysqli = new mysqli("localhost","root","","bbs");
$mysqli->set_charset("utf8");
$result=$mysqli->query("select * from news");
/*
$data = array();
while($row = $result->fetch_assoc())
{
$data[] = $row;
}
把所有的结果保存到一个数组里面去,然后用它们用于前台一次性显示出来
首先是foreach 的用法
{foreach $data as $row}
{$row.id}---{$row.title}----{$row.content}</br>
{/foreach}
*/
$data = array();
while($row = $result->fetch_assoc())
{
$data[]=$row;
}
$smarty->assign("data",$data);
/*
* {section name="i" loop=$data}
{$data[i].id}---{$data[i].title}---{$data[i].content}</br>
{/section}
*
* */
$smarty->display("innerfun.html");
/*
*
* foreach() 可以遍历索引和非索引数组,而
* section 只能遍历索引数组
*
* */
?>
Smarty foreach Section
最新推荐文章于 2018-06-11 13:30:16 发布