您的位置:首页 > 数据库

smarty 对数据库的简单操作。

2010-06-19 22:28 183 查看


smarty简单配置

-------------------------------------smarty_inc.php--------------------------------------------

<?php
include_once("./smarty/Smarty.class.php");
$smarty=new Smarty();
$smarty->config_dir="smarty/Config_File.class.php";//目录变量
$smarty->caching=false;//是否使用缓存
$smarty->template_dir="./templates";//设置模板目录
$smarty->compile_dir="./templates_c";//设置编译目录
$smarty->cache_dir="./smarty_cache";//缓存文件夹
$smarty->left_delimiter="{";
$smarty->right_delimiter="}";
?>

----------------------------------index.php---------------------------------------------------

<?php

include("config.php");
$sql=mysql_query("select * from xinxi order by id desc");
while($row=mysql_fetch_array($sql)){
$arrdata[]=$row;
}
$smarty->assign("xx",$arrdata);
$smarty->display("index.htm");
?>

-----------------------------------index.htm 模板文件 主要操作 如何应用section循环二维数组--------------------------------------------

<?php include("config.php");?>
<html

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<hr />
<a href="">首页</a>|<a href="">流言</a>|
<hr />
<body>

<form action="" method="post" name="form2">
<table bgcolor="#FFFFCC" width="800" align="left" cellpadding="0" cellspacing="1">
<tr >
<tr>
<td align="center" width="50" height="20">标题
</td>
<td align="center" width="300" height="20">内容
</td>
<td align="center" width="100" height="20">留言时间
</td>
</tr>
{section name=list loop=$xx} //主要显示代码
<tr>
<td align="center" width="50">
<input name="del[]" type="checkbox" value="" />

</td>
<td align="center" width="50" height="20">{$xx[list].title}
</td>
<td align="left" width="300" height="20">{$xx[list].content}
</td>
<td align="center" width="100" height="20">{$xx[list].createtime}
</td>
</tr>
{/section}
</tr>
<tr>

<td width="6">
</td>
<td width="200" >

</td>
</tr>
</table>
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: