smarty单页面多缓存文件齐全

本文介绍如何使用PHP和Smarty模板引擎从数据库获取数据并展示到网页上,包括数据库连接、查询、数据处理和Smarty模板的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一: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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值