PHP文件原代码:
include_once("./comm/Smarty.class.php"); //包含smarty类文件
define("NUM", 5); //定义每次显示的新闻条数
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->templates_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->cache_dir = "./cache"; //设置缓存目录
$smarty->cache_lifetime = 60 * 60 * 24; //设置缓存时间
$smarty->caching = false; //这里是调试时设为false,发布时请使用true
$smarty->left_delimiter = "<{"; //设置左边界符
$smarty->right_delimiter = "}>"; //设置右边界符
$db=mysql_connect('localhost','root','123456');
mysql_select_db('liu',$db);
$sql="select id,title from lyb";
mysql_query("set names gb2312");
$result=mysql_query($sql,$db);
while($row=mysql_fetch_array($result)){
$array[]=array("id"=>$row['id'],
"title"=>$row['title']);
}
mysql_close();
$smarty->assign('new',$array);
$smarty->display('3.html');
?>
3.html
<{section name=loop loop=$new}> <{$new[loop].id}> <{$new[loop].title}> <{/section}> |