现在的位置: 首页 > 综合 > 正文

php的smarty循环

2013年12月13日 ⁄ 综合 ⁄ 共 707字 ⁄ 字号 评论关闭

<?php
require_once("include/config_base.php");
require 'libs/Smarty.class.php';
$db = new DedeSql(false);
$smarty = new Smarty;
$smarty->compile_check = true;
$db->SetQuery("Select id,title From #@__archives  where iscommend=11 order by id desc limit 0,8");
$db->Execute();
while($nrow = $db->GetObject())
{
    $news_list[]=array("id"=>$nrow->id,"title"=>mb_substr($nrow->title,0,15,'gbk'));
}
$str=@file_get_contents("http://weather.265.com/weather.htm");
$str=str_replace("<scrīpt>","</body>",$str);
$smarty->assign("news ",$ news_list);
$smarty->assign("weatherstr",$str);
$smarty->display('index.html');
?>

Index.html
循环{section name=loop loop=$news}
<a href="plus/view.php?aid={$news[loop].id}">{$news[loop].title}</a><br />
{/section}
天气{$weatherstr }

 

抱歉!评论已关闭.