<? $result=mysql_query("SELECT * FROM `bbs_forum_post` where tid ='$tid'"); while($row=mysql_fetch_array($result)){ ?> <?=$row[message]?> <? } ?> 我的这个代码在独立页面可以运行,加入到模板页也是空白,是怎么回事
discuz有自己的数据库类 封装了很多方法 也包含安全过滤$query = $db->query("select * from bbs_forum_post where tid ='$tid' "); while($result = $db->fetch_array($query)) { $mythread[] = $result; }你这段 改成$tid = intval($tid); $mythread = DB::fetch_all('select * from '.DB::table('forum_post').' where tid = $tid');
10楼代码有误最后包含$tid的单引号改成双引号
谢谢 wander_wind弄好了,但是$tid =$_GET['tid'];这个得不到值我想让他在列表页每个帖子的下边出现,如何获得每个帖子的tid或都 $mythread = DB::fetch_all('select * from '.DB::table('forum_post').' where tid = $tid'); 这一句能不能直接加到模板里,我加了显示空白,要是能加就简单多了
有什么好的工具可以推荐下
2、打印相关变量看看,在哪一行出现错误
目测 $db不存在吧,dx3以后不支持这种写法了
$result=mysql_query("SELECT * FROM `bbs_forum_post` where tid ='$tid'");
while($row=mysql_fetch_array($result)){
?>
<?=$row[message]?>
<?
}
?>
我的这个代码在独立页面可以运行,加入到模板页也是空白,是怎么回事
while($result = $db->fetch_array($query)) {
$mythread[] = $result;
}你这段 改成$tid = intval($tid);
$mythread = DB::fetch_all('select * from '.DB::table('forum_post').' where tid = $tid');
$mythread = DB::fetch_all('select * from '.DB::table('forum_post').' where tid = $tid');
这一句能不能直接加到模板里,我加了显示空白,要是能加就简单多了
可以直接加进模板
<!--{eval $mythread = DB::fetch_all('select * from '.DB::table('forum_post')." where tid = $tid");}-->
eval 就是直接运行php的标签
模板调用的帖子列表是$_G['forum_threadlist'],在末尾include template......引入模板的代码之前,遍历这个列表变量就可以处理
<div class="listjj"><!--{eval $mythread = DB::fetch_all('select * from '.DB::table('forum_post')." where tid = $thread[tid]");}--><!--{loop $mythread $key $val}-->
{$val[message]}
<!--{/loop}--></div>还是得不到 tid
<!--{eval $mythread = DB::fetch_all('select * from '.DB::table('forum_post')." where tid = $tid");}-->
也不行
这个文件里 我找不到 标题subject怎么定义的,要是加在它的下边就 不用单独找tid了吧
实在不行就按15楼那样试试
那说明代码没错,看看$thread[tid]有什么问题,echo一下,或者用$tid=它,接收放进eval再试试
今天偷偷水了好久csdn,还半小时下班,突击一下无聊的工作进度去
兄弟你自己想想办法哈
$thread[tid] 是不是不能放在<!--{eva 里边
能在这里直接输出就好了