conn.php<?php
$mylink=mysql_connect("localhost","root","");
mysql_select_db("test",$mylink);
?>
liuyan.php<?php
include ("conn.php");
$query=mysql_query("select * from news");
while ($r=mysql_fetch_array($query))
{
$array[]=array('time'=>$r['time'],'title'=>$r['title']);
}
$smarty=new Smarty();
$smarty->template_dir="./templates";
$smarty->compile_dir="./templates_c";
$smarty->config_dir="./configs";
$smarty->cache_dir="./cache";
$smarty->assign("array","$array");
$smarty->display('liuyan.tpl');
?>
liuyan.tpl{section loop=$array name=loop}
{$array[loop].time}
<hr>
{$array[loop].title}
<hr>
{sectionelse}
无消息
{/section}
$mylink=mysql_connect("localhost","root","");
mysql_select_db("test",$mylink);
?>
liuyan.php<?php
include ("conn.php");
$query=mysql_query("select * from news");
while ($r=mysql_fetch_array($query))
{
$array[]=array('time'=>$r['time'],'title'=>$r['title']);
}
$smarty=new Smarty();
$smarty->template_dir="./templates";
$smarty->compile_dir="./templates_c";
$smarty->config_dir="./configs";
$smarty->cache_dir="./cache";
$smarty->assign("array","$array");
$smarty->display('liuyan.tpl');
?>
liuyan.tpl{section loop=$array name=loop}
{$array[loop].time}
<hr>
{$array[loop].title}
<hr>
{sectionelse}
无消息
{/section}
index.php中还有
include ("../libs/Smarty.class.php");