免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2468 | 回复: 8
打印 上一主题 下一主题

[已解决]一个smarty的问题!麻烦各位了! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-30 09:54 |只看该作者 |倒序浏览
首先有3个页面
header.php   对应 header.htm
index.php      对应  index.htm
footer.php    对应  footer.htm

在 index.htm中引用了header.htm和footer.htm   用的是{include file="header.htm"}和{include file="footer.htm"}

现在问题是

我在header.php写入数据库查询语句   整个页面[index.php]没有显示   (其实,我是想把数据库中的网站头部信息和页脚信息放在header.php和footer.php中完成)
而我在index.php中写入查询语句  整个页面[index.php]有显示,可以看到完整的头部和页脚信息

请问这是为什么呢?
3个PHP页面都引用了Smarty.class.php  和数据库链接文件

[ 本帖最后由 szgekko 于 2008-2-2 08:48 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-01-30 10:14 |只看该作者
代码发上来

论坛徽章:
0
3 [报告]
发表于 2008-01-30 10:22 |只看该作者
在模板中include其他模板,index.php当然不知道去执行你的header.php,
不要把模板和程序混淆了

论坛徽章:
0
4 [报告]
发表于 2008-01-30 10:23 |只看该作者
header.php

  1. <?php
  2. require_once("include/config.php");
  3. require_once("libs/Smarty.class.php");

  4. $smarty = new Smarty;

  5. $query_s=mysql_query("SELECT * FROM `basic` WHERE `id`='1'");
  6. $list_arr=mysql_fetch_array($query_s);

  7.         $title=$list_arr["title"];
  8.         $description=$list_arr["description"];
  9.         $keywords=$list_arr["keywords"];
  10.         $comname=$list_arr["comname"];
  11.         $comadd=$list_arr["comadd"];
  12.         $comtel=$list_arr["comtel"];
  13.         $comfax=$list_arr["comfax"];
  14.         $email=$list_arr["email"];
  15.         $beian=$list_arr["beian"];

  16. $smarty->assign("title",$title);
  17. $smarty->assign("description",$description);
  18. $smarty->assign("keywords",$keywords);
  19. $smarty->assign("comname",$comname);
  20. $smarty->assign("comadd",$comadd);
  21. $smarty->assign("comtel",$comtel);
  22. $smarty->assign("comfax",$comfax);
  23. $smarty->assign("beian",$beian);
  24. $smarty->assign("email",$email);

  25. $smarty->display('header.htm');
  26. ?>
复制代码
其他PHP页面结构一样 就是最后的$smarty->display('header.htm');不同

论坛徽章:
0
5 [报告]
发表于 2008-01-30 10:24 |只看该作者
原帖由 hshq_cn 于 2008-1-30 10:22 发表
在模板中include其他模板,index.php当然不知道去执行你的header.php,
不要把模板和程序混淆了

明白了  谢谢

哪这样
模板页以后就不用{include file="footer.htm"}了?
全部都在  php页面  requrie_once()  ??

[ 本帖最后由 szgekko 于 2008-1-30 10:28 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2008-01-30 10:51 |只看该作者
include require不就是用来组织代码的嘛,
是在程序中还是模板中,这就要看具体应用了,
怎么方便怎么来

论坛徽章:
0
7 [报告]
发表于 2008-01-30 11:33 |只看该作者
原帖由 hshq_cn 于 2008-1-30 10:51 发表
include require不就是用来组织代码的嘛,
是在程序中还是模板中,这就要看具体应用了,
怎么方便怎么来

非常感谢!!!

论坛徽章:
0
8 [报告]
发表于 2008-02-01 23:11 |只看该作者
应该include_php

论坛徽章:
0
9 [报告]
发表于 2008-02-14 13:31 |只看该作者
index.php没有调用header.php运行
就这么简单
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP