smarty_smart和mysql的搭配应用

来源:互联网 发布:天使爱美丽影评 知乎 编辑:程序博客网 时间:2024/04/30 17:46

smart和mysql的搭配应用

1>MysqlAndSmarty.php代码如下:
<?php

include("smarty_inc.php");
include("mysql_inc.php");


if($_GET[id]){      //判断地址栏是否有传入值
$sql="SELECT * FROM tb_info WHERE id=".$_GET[id] ;   //根据传入的值从数据库中查询需要的数据
$query=$db->query($sql);
$row=$db->fetch_array($query);
}

$smarty->assign('row',$row);     //将从mysql中查询到的资料兑换成smarty变量 
$smarty->assign('id',$_GET[id]);
$smarty->display('MysqlAndSmarty.htm ');   //引入要显示的模板
?>


2>templates/MysqlAndSmarty.htm代码如下:
{section name=name loop=$row}
<font color=red>{$row[name]}&nbsp;&nbsp;&nbsp;</font>
{/section}

地址栏输入"http://localhost/news/MysqlAndSmarty.php?id=9"运行结果如下:
9   招聘信息   湖南红阳网络有限公司招聘   我公司现招聘,PHP网络工程师一名。    肖红阳995702784   1   2009-04-22 16:00:54    

原创粉丝点击