<?php //导入smarty文件 require 'Smarty.class.php'; //导入数据库连接文件 require 'lib/db.php'; //实例化smarty $smarty = new Smarty; //设置smarty属性 $smarty->compile_check = true; $smarty->debugging = true; //操作数据库 $mysql="select * from article order by subtime Desc"; $results = mysql_query($mysql); //读取数据为二维数组然后传值给smarty,下边是读取数组的代码 /* {section name=list loop=$row} * {$row[list].title}<br/> * {$row[list].content} * {/section} */ while($row[] = mysql_fetch_assoc($results)){ $smarty->assign("row",$row); } //调用模板 $smarty->display("index.tpl"); ?>