smarty_smart和mysql的搭配应用

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     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值