一:php文件table.php
<?php
include 'libs/Smarty.class.php';
$smarty=new Smarty();
$smarty->caching=1;
$smarty->template_dir="demo1/templates";
$smarty->compile_dir="demo1/templates_c";
$smarty->config_dir="demo1/templates";
$smarty->cache_dir="demo1/cache";
$smarty->left_delimiter="<{";//界定符
$smarty->right_delimiter="}>";
$link=mysql_connect('localhost','root','');
mysql_select_db('ec',$link);
mysql_query('set names utf8');
if(!$smarty->is_cached('table.tpl',$_GET["id"])){
$sql="select * from brand where id=".$_GET["id"];
$result=mysql_query($sql);
$i=0;
$array=array();
while($row=mysql_fetch_assoc($result)){
$array[$i]=$row;$i++;
}
$smarty->assign('b',$array);
echo '没有被缓存';
}
$smarty->display("table.tpl",$_GET["id"]);
?><?php
include 'libs/Smarty.class.php';
$smarty=new Smarty();
$smarty->caching=1;
$smarty->template_dir="demo1/templates";
$smarty->compile_dir="demo1/templates_c";
$smarty->config_dir="demo1/templates";
$smarty->cache_dir="demo1/cache";
$smarty->left_delimiter="<{";//界定符
$smarty->right_delimiter="}>";
$link=mysql_connect('localhost','root','');
mysql_select_db('ec',$link);
mysql_query('set names utf8');
if(!$smarty->is_cached('table.tpl',$_GET["id"])){
$sql="select * from brand whereid=".$_GET["id"];
$result=mysql_query($sql);
$i=0;
$array=array();
while($row=mysql_fetch_assoc($result)){
$array[$i]=$row;$i++;
}
$smarty->assign('b',$array);
echo '没有被缓存';
}
$smarty->display("table.tpl",$_GET["id"]);
?>
二:tpl文件 table.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<hr />
<center><table bgcolor="#FFFF99"border="1">
<{section name=stu1 loop=$b}>
<caption><{$b[stu1].brand_name}>的详细信息</caption>
<tr><td>学号:</td><td><{$b[stu1].id}></td></tr>
<tr><td>姓名:</td><td><{$b[stu1].brand_name}></td></tr>
<tr><td>地址:</td><td><{$b[stu1].brand_url}></td></tr>
<tr><td>地址:</td><td><{$b[stu1].brand_desc}></td></tr>
<tr><td>地址:</td><td><{$b[stu1].sort_order}></td></tr>
<{/section}>
</table>
</center>
</body>
</html>