【澳门新葡亰平台官网】灵动标签调用外部数据|如Discuz、DiscuzX、PHPwind

用灵动标签调用外部数据: 例一:调用Discuz的最新贴子

关键字描述:帖子 方法 论坛 调用 &nbsp &quot &lt tid function fid

USE 数据库名称1;
DROP PROCEDURE IF EXISTS 数据库名称1.存储过程名称;
delimiter $$
CREATE PROCEDURE 数据库名称1.存储过程名称(in v_count bigint,in
v_count2 bigint)
BEGIN
set @vCount1=v_count;
set @vCount2=v_count2;

table width=100% border=0 cellspacing=1 cellpadding=3 [e:loop={select
tid,subject,dateline from discuzdb.cdb_threads order by tid desc limit
10,10,24,0}] trtd a href=/bbs/viewthread.php?tid=?=$bqr[tid]?
target=_blank?=$bqr[subject]?/a (?=date(‘Y-m-d’,$bqr[dateline])?)
/td/tr [/e:loop] /table

今天我告诉大家一些在织梦dedecms里面调用discuz论坛帖子的一些方法,这些方法都是好不容易从网上搜来的,这次一次奉献给大家啦。

set @i=1;
set @vintervala=10000;
set @vintervalb=10000;
while(@i<=@vCount1)
do
#随机获取一个版块ID
select fid into @vfid from tps_forum_forum where fup<>0 and
`type`=’forum’ and `status`=1 order by rand() limit 1;

discuzdb.cdb_threads为Discuz的贴子表名,其中discuzdb为Discuz的数据库名称。
limit 10为显示贴子数量。
如果用伪静态地址可以用:/bbs/thread-?=$bqr[tid]?-1-1.html
如果指定单个版块的贴子,SQL用:select tid,subject,dateline from
discuzdb.cdb_threads where fid=版块ID order by tid desc limit 10
如果指定多个版块的贴子,SQL用:select tid,subject,dateline from
discuzdb.cdb_threads where fid in (1,2,3) order by tid desc limit 10
例二:调用Discuz的最新贴子

  首先要注意的是下面的代码中都有table=”cdb_threads”这句。这句不是适用所有网站的,这个地方cbd是你论坛的表前缀名称,大家根据自己的论坛修改成合适的表前缀名。再者,我是把织梦和discuz
论坛放在一个数据库里面的,才开始放在两个数据库,整合了半天不成功,不知道是什么原因。后面放在一个数据库里面成功了。但是没有在放到两个数据库里面做测试,大家也可以测试下,告诉我结果了。按道理来说不限制放进同一个数据库才合理些!最后m-d
H:M 带表是发布的时间,如果只要(日-月)时间格式的,把 H:M去掉即可。

#获取pid
select ifnull(max(pid)+1,1) into @vpid from tps_forum_post;

table width=100% border=0 cellspacing=1 cellpadding=3 [e:loop={select
tid,subject,dateline,fid from discuzdb.cdb_threads order by tid desc
limit 10,10,24,0}] ?php $fr=$empire-fetch1(select name from
discuzdb.cdb_forums where fid=’$bqr[fid]’); ? trtd [?=$fr[name]?]
a href=/bbs/viewthread.php?tid=?=$bqr[tid]?
target=_blank?=$bqr[subject]?/a (?=date(‘Y-m-d’,$bqr[dateline])?)
/td/tr [/e:loop] /table

  1、论坛最新主题调用代码如下:

#获取tid
select ifnull(max(tid)+1,1) into @vtid from tps_forum_post;

discuzdb.cdb_forums为Discuz的版块表名,其中discuzdb为Discuz的数据库名称。
例三:调用DiscuzX的最新贴子

{dede:loop table=”cdb_threads” sort=”tid” row=”10″}
<a href=”/bbs/viewthread.php?tid=[field:tid%20/]”>
·[field:subject function=”cn_substr(‘@me’,30)” /]([field:lastpost
function=”date(‘m-d H:M’,’@me’)” /])</a>
<br/>
{/dede:loop}

#获取发帖的storeid username
select m.uid,m.username into @vuida,@vusernamea from tps_common_member
m where m.uid>4 and m.`status`=0 order by rand() limit 1,1;

table width=100% border=0 cellspacing=1 cellpadding=3 [e:loop={select
tid,subject,dateline from discuzdb.pre_forum_thread order by tid desc
limit 10,10,24,0}] trtd a
href=/bbs/forum.php?mod=viewthreadtid=?=$bqr[tid]?
target=_blank?=$bqr[subject]?/a (?=date(‘Y-m-d’,$bqr[dateline])?)
/td/tr [/e:loop] /table

这个连接地址你可以写相对路径,也可以写绝对路径。

set @vintervala=@vintervala+@i;
set @vintervalb=@vintervalb+@i*100;

discuzdb.pre_forum_thread为DiscuzX的贴子表名,其中discuzdb为DiscuzX的数据库名称。
limit 10为显示贴子数量。
如果用伪静态地址可以用:/bbs/thread-?=$bqr[tid]?-1-1.html
如果指定单个版块的贴子,SQL用:select tid,subject,dateline from
discuzdb.pre_forum_thread where fid=版块ID order by tid desc limit 10
如果指定多个版块的贴子,SQL用:select tid,subject,dateline from
discuzdb.pre_forum_thread where fid in (1,2,3) order by tid desc limit
10 例四:调用DiscuzX的最新贴子

  如果是discuz动态论坛,链接地址如
/]

set @vtitlea=concat(‘发帖标题’,floor(1+RAND()*10000000));
set
@vpostdate=unix_timestamp(DATE_FORMAT(LOCALTIME()+@vintervala,’%Y-%m-%d
%H:%i:%S’));

table width=100% border=0 cellspacing=1 cellpadding=3 [e:loop={select
tid,subject,dateline,fid from discuzdb.pre_forum_thread order by tid
desc limit 10,10,24,0}] ?php $fr=$empire-fetch1(select name from
discuzdb.pre_forum_forum where fid=’$bqr[fid]’); ? trtd
[?=$fr[name]?] a
href=/bbs/forum.php?mod=viewthreadtid=?=$bqr[tid]?
target=_blank?=$bqr[subject]?/a (?=date(‘Y-m-d’,$bqr[dateline]澳门新葡亰平台官网,)?)
/td/tr [/e:loop] /table

  如果是discuz静态论坛,连接地址如
/]-1-1.html

set @vip=’192.168.1.1′;
set @vmessagea=concat(‘发帖内容’,floor(1+RAND()*10000000),’rn’);
set @vporta=floor(10000+RAND()*55535);

discuzdb.pre_forum_forum为DiscuzX的版块表名,其中discuzdb为DiscuzX的数据库名称。
例五:调用PHPwind的最新贴子

2、论坛指定版块帖子调用方法:

#set @vportb=floor(10000+RAND()*55535);
set @vmessageb=concat(‘回复的第’,@vtid,’个帖子的内容’);

table width=100% border=0 cellspacing=1 cellpadding=3 [e:loop={select
tid,subject,postdate from phpwinddb.pw_threads order by tid desc limit
10,10,24,0}] trtd a href=/bbs/read.php?tid=?=$bqr[tid]?
target=_blank?=$bqr[subject]?/a (?=date(‘Y-m-d’,$bqr[postdate])?)
/td/tr [/e:loop] /table

{ dede:loop table=”cdb_threads” if=”fid=1 or fid=2 and
displayorder!=-1″ sort=”tid” row=”6″ }
<a href=”/bbs/viewthread%20dot%20php?tid=[field:tid%20/]”
target=”_blank”>
·[field:subject function=”cn_substr(‘ @ me’,50)” /] </a>
<br/>
{ /dede:loop }

#3新增发送帖子的信息
INSERT INTO `tps_forum_post` (`pid`, `fid`, `tid`, `first`,
`author`, `authorid`, `subject`, `dateline`, `message`,
`useip`, `port`,
`invisible`, `anonymous`, `usesig`, `htmlon`, `bbcodeoff`,
`smileyoff`, `parseurloff`, `attachment`, `rate`, `ratetimes`,
`status`, `tags`, `comment`, `replycredit`, `position`)
VALUES (@vpid, @vfid, @vtid, 1, @vusernamea, @vuida,
@vtitlea,@vpostdate,@vmessagea, @vip, @vporta, 0, 0, 1, 0, -1, -1, 0, 0,
0, 0, 0, ”, 0, 0, 1);

phpwinddb.pw_threads为phpwind的贴子表名,其中phpwinddb为phpwind的数据库名称。
limit 10为显示贴子数量。
如果用伪静态地址可以用:/bbs/read-htm-tid-?=$bqr[tid]?.html
如果指定单个版块的贴子,SQL用:select tid,subject,postdate from
phpwinddb.pw_threads where fid=版块ID order by tid desc limit 10
如果指定多个版块的贴子,SQL用:select tid,subject,postdate from
phpwinddb.pw_threads where fid in (1,2,3) order by tid desc limit 10
例六:调用PHPwind的最新贴子

其中的fid=1 or
fid=2是论坛主题分类id,可以按照自己要求来修改,如果是一个分类就直接写fid=x

#最新主题信息表
INSERT INTO `tps_forum_newthread` (`tid`, `fid`, `dateline`)
VALUES (@vtid,@vfid, @vpostdate);

table width=100% border=0 cellspacing=1 cellpadding=3 [e:loop={select
tid,subject,postdate,fid from phpwinddb.pw_threads order by tid desc
limit 10,10,24,0}] ?php $fr=$empire-fetch1(select name from
phpwinddb.pw_forums where fid=’$bqr[fid]’); ? trtd [?=$fr[name]?]
a href=/bbs/read.php?tid=?=$bqr[tid]?
target=_blank?=$bqr[subject]?/a (?=date(‘Y-m-d’,$bqr[postdate])?)
/td/tr [/e:loop] /table

3、论坛调精华主题调用代码如下:

#分表协调信息表
insert into tps_forum_post_tableid values();

phpwinddb.pw_forums为phpwind的版块表名,其中phpwinddb为phpwind的数据库名称。
其他说明:
1、帝国CMS的数据库帐号要有select权限查询对应数据库的表,才能读取成功。
2、SQL调用支持调用mysql数据库的所有数据,上面只是举了几个例子。

{dede:loop table=”cdb_threads” if=”displayorder!=-1″ sort=”tid”
row=”10″}
<a href=”/bbs/viewthread.php?tid=[field:tid%20/]”>
·[field:subject function=”cn_substr(‘@me’,30)” /]([field:lastpost
function=”date(‘m-d H:M’,’@me’)” /])</a>
<br/>
{/dede:loop}

#假设1个帖子有50000个回复
set @j=1;
while(@j<=@vCount2)
do
#获取回帖的storeid username
select m.uid,m.username into @vuidb,@vusernameb from tps_common_member
m where m.uid>4 and m.`status`=0 order by rand() limit 1000,1;

如果想调用某个板块的精华主题代码如下:

#获取pid
select ifnull(max(pid)+1,1) into @vpid from tps_forum_post;

{dede:loop table=”cdb_threads” if=”fid=5 and displayorder!=-1″
sort=”tid” row=”10″}
<a href=”/bbs/viewthread.php?tid=[field:tid%20/]”>
·[field:subject function=”cn_substr(‘@me’,30)” /]([field:lastpost
function=”date(‘m-d H:M’,’@me’)” /])</a>
<br/>
{/dede:loop}

set
@vreplaydate=unix_timestamp(DATE_FORMAT(LOCALTIME()+@vintervalb,’%Y-%m-%d
%H:%i:%S’));

其中的fid=5是论坛主题分类id,可以按照自己要求来修改,

set @vposition=@j+1;

  如果想调用论坛所有的板块的最新精华主题只要去掉fid=5 and 就可以了。

#2分表协调表
insert into tps_forum_post_tableid values();

  4、调用的帖子列表这可以按查看次数排序,代码如下:

#3新增回复帖子的信息
INSERT INTO `tps_forum_post` (`pid`, `fid`, `tid`, `first`,
`author`, `authorid`, `subject`, `dateline`, `message`,
`useip`, `port`,
`invisible`, `anonymous`, `usesig`, `htmlon`, `bbcodeoff`,
`smileyoff`, `parseurloff`, `attachment`, `rate`, `ratetimes`,
`status`, `tags`, `comment`, `replycredit`, `position`)
VALUES (@vpid, @vfid, @vtid, 0, @vusernameb, @vuidb, ”, @vreplaydate,
@vmessageb, @vip, @vporta, 0, 0, 1, 0, -1, -1, 0, 0, 0, 0, 0, ‘0’, 0, 0,
@vposition);

{dede:loop table=”cdb_threads” sort=”views” row=”10″}
<a href=”/dz/viewthread.php?tid=[field:tid%20/]”>
·[field:subject function=”cn_substr(‘@me’,30)” /]([field:lastpost
function=”date(‘m-d H:M’,’@me’)” /])</a>
<br/>
{/dede:loop}
其中sort=”views” 就是控制按照查看次数排序的代码

#主题参与者记录表,第1个回复的帖子信息
INSERT INTO `tps_forum_threadpartake` (`tid`, `uid`,
`dateline`)
select tid,authorid,dateline
from tps_forum_post where fid=@vfid and tid=@vtid and first=0 and
position=2;

5、论坛置顶版块帖子调用方法举例:

#主题参与者记录表,第@vCount2+1个回复的帖子信息
INSERT INTO `tps_forum_threadpartake` (`tid`, `uid`,
`dateline`)
select tid,authorid,dateline
from tps_forum_post where fid=@vfid and tid=@vtid and first=0 and
position=@vCount2+1;

{ dede:loop table=”cdb_threads” sort=”dateline” if=”fid=’3′ and
typeid=’51′” row=”10″ }
<a href=”/a/bbs/viewthread%20dot%20php?tid=[field:tid%20/]”
target=”_blank”>
·[field:subject function=”cn_substr(‘ @ me’,30)” /]</a>
<br>
{ /dede:loop }

COMMIT;

6、论坛版块名称调用方法:

set @j=@j+1;
end while;

{ dede:loop table=”cdb_forums” sort=”displayorder” row=”16″ col=”4″ }
<a href=”/bbs/viewthread dot php?fid=[field:fid
/]”>·[field:name function=”cn_substr(‘ @me’,30)” /] </a>
{ /dede:loop }

#获取position
select max(position) into @vposition from tps_forum_post where first=0
and tid=@vtid;
select count(0) into @vreplay from tps_forum_post where first=0 and
tid=@vtid;
select max(dateline) into @vreplaydate from tps_forum_post where
first=0 and tid=@vtid;

注:这种方法这个还有点问题,它会将论坛分区、版块都调出来。望达人改进!

#1论坛主题信息表
INSERT INTO `tps_forum_thread` (`tid`, `fid`, `posttableid`,
`typeid`, `sortid`, `readperm`, `price`, `author`,
`authorid`, `subject`, `dateline`, `lastpost`,
`lastposter`, `views`, `replies`, `displayorder`, `highlight`,
`digest`, `rate`, `special`, `attachment`, `moderated`,
`closed`, `stickreply`, `recommends`,
`recommend_add`, `recommend_sub`, `heats`, `status`,
`isgroup`, `favtimes`, `sharetimes`, `stamp`, `icon`,
`pushedaid`, `cover`, `replycredit`, `relatebytag`,
`maxposition`, `bgcolor`, `comments`, `hidden`)
VALUES (@vtid,@vfid, 0, 0, 0, 0, 0, @vusernamea, @vuida, @vtitlea,
@vpostdate, @vreplaydate,@vusernamea, floor(1000+rand()*10000),
@vreplay, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, floor(0+rand()*2), 32, 0, 0, 0, -1, -1, 0, 0, 0, ‘0’,
@vposition, ”, 0, 0);

附:dedecms的LOOP 标记规则

#获取版块内主题数量
select count(0) into @vthreadCount from tps_forum_thread where
fid=@vfid;

  功能说明:用于调用任意表的数据,一般用于调用论坛贴子之类的操作

#获取版块内发帖子数量
select count(0) into @vpostCount from tps_forum_post where first=1 and
fid=@vfid;

  适用范围:所有模板

#获取今日发帖数量
select count(0) into @vtodayposts from tps_forum_post where first=1
and fid=@vfid
and dateline>=unix_timestamp(date_format(localtime(),’%Y-%m-%d’))
and
dateline<=unix_timestamp(DATE_ADD(date_format(localtime(),’%Y-%m-%d’),INTERVAL
24*60*60-1 SECOND));

  基本语法:

#获取发帖综合信息
select fp.pid,fp.message,fp.dateline,fp.author into
@vpid,@vmessage,@vdateline,@vauthor
from tps_forum_post fp where first=1 and fid=@vfid order by dateline
desc limit 1;

  { dede:loop table=’ sort=” row=” if=” }

#更新版块表中 主题 帖子 今日发帖数据 及发帖综合信息
update tps_forum_forum ff set
ff.threads=@vthreadCount,ff.posts=@vpostCount,ff.todayposts=@vtodayposts,
ff.lastpost=concat(@vpid,@vmessage,@vdateline,@vauthor) where
ff.fid=@vfid;

  [1] table 表示查询的数据表

COMMIT;

  [2] sort 用于排序的字段 也可以加”views”(查看次数排列)

set @i=@i+1;

  [3] row 返回结果的条数

END WHILE;
end $$
delimiter ;

  [4] if 查询条件

call 数据库名称1.存储过程名称(3,10);

7、调用论坛帖子中的图片方法,网上搜到的,我自己还没有做测试。

{dede:sql
sql=”SELECT`cdb_attachments`.`aid`,`cdb_attachments`.`attachment`,`cdb_threads`.`tid`,
`cdb_threads`.`fid`,`cdb_threads`.`subject` FROM
`cdb_attachments` LEFT JOIN `cdb_threads`

ON`cdb_threads`.`tid`=`cdb_attachments`.`tid` WHERE
`cdb_attachments`.`readperm`=’0′ AND`displayorder`>=’0′ AND
`filetype`=’image/pjpeg’ GROUP BY tid LIMIT 0,1 “}
<a href=”/bbs/viewthread.php?tid=[field:tid%20/]”>
<img src=”/bbs/attachments/[field:attachment/]”
ALT=”[field:subject/]” width=”100″ height=”80″ border=”0″ />
</A>
{/dede:sql}

原文地址:

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图