oghuz 发表于 2005 年 12 月 18 日 13:41:36

Discuz论坛帖子首页调用(菜鸟简洁版)原理

分5步:
1:从数据库找到源数据
2:需要什么数据
3:执行SQL得到数据
4:格式化数据
5:调用JS

1:从数据库找到源数据,在discuz_threads,自己用PHPMYADMIN导出--
-- 表的结构 `discuz_threads`
--

CREATE TABLE `discuz_threads` (
`tid` mediumint(8) unsigned NOT NULL auto_increment,
`fid` smallint(6) unsigned NOT NULL default '0',
`creditsrequire` smallint(6) unsigned NOT NULL default '0',
`iconid` smallint(6) unsigned NOT NULL default '0',
`author` char(15) NOT NULL default '',
`authorid` mediumint(8) unsigned NOT NULL default '0',
`subject` char(80) NOT NULL default '',
`dateline` int(10) unsigned NOT NULL default '0',
`lastpost` int(10) unsigned NOT NULL default '0',
`lastposter` char(15) NOT NULL default '',
`views` mediumint(8) unsigned NOT NULL default '0',
`replies` smallint(6) unsigned NOT NULL default '0',
`displayorder` tinyint(1) NOT NULL default '0',
`highlight` tinyint(1) NOT NULL default '0',
`digest` tinyint(1) NOT NULL default '0',
`blog` tinyint(1) NOT NULL default '0',
`poll` tinyint(1) NOT NULL default '0',
`attachment` tinyint(1) NOT NULL default '0',
`closed` mediumint(8) unsigned NOT NULL default '0',
`threads_moderatetime` char(15) NOT NULL default '',
`threads_moderate` tinyint(1) NOT NULL default '0',
`threads_moderator` char(15) NOT NULL default '',
`threads_moderatorid` char(8) NOT NULL default '',
`authornick` char(15) NOT NULL default '',
PRIMARY KEY(`tid`),
KEY `displayorder` (`fid`,`displayorder`,`lastpost`),
KEY `digest` (`digest`)
) TYPE=MyISAM AUTO_INCREMENT=10 ;

--
-- 导出表中的数据 `discuz_threads`
--

INSERT INTO `discuz_threads` VALUES (1, 4, 0, 0, '懑梵', 5, '晕死', 1128577768, 1128623748, 'macrolong', 42, 9, 0, 0, 0, 0, 0, 0, 0, '1128577768', 0, '懑梵', '5', '');

2:需要什么数据看到了把,帖子的N个属性,这几个是关键的,subject(标题),dateline(发表时间),lastpost(最后回复),replies(回复数),其他一样,很好理解的 ,就要着几个。

3:执行SQL得到数据
$result=@mysql_query("SELECT * FROM `$discuz_table` ORDER BY `lastpost` DESC LIMIT 0,$post");
while ($row = mysql_fetch_array($result)) {
 $subject=(strlen($row)<=$titlelength)?$row:(m_substr($row,0,$titlelength)."..");
 $date=date("y-m-d",$row);
 $linedate=date("Y-m-d H:i:s",$row);
 $postdate=date("Y-m-d H:i:s",$row);
 $views=$row;
}

4:格式化数据
$discuz_lastpost.="<TR><TD>◇<a href=bbs/viewthread.php?tid=$row title='$title'>$subject</a></TD><TD>$date</TD></TR>";

5:调用JS

把discuz_js.php放在论坛根目录;再在调用页添加以下JS:
<script src="discuz/discuz_js.php?new=8&post=3&hot=6"></script>new=8&post=3&hot=6可以选择你所需要的参数,也可以不要,既可以这样:new=8或者post=3或者hot=6或者new=8&post=3或者post=3&hot=6

简单把,其他什么精华贴,置顶贴都相似,有兴趣的可以自己写。希望这编文章对大家有用。
完整的代码如下:
<?php
// ========================== 文件说明 ==========================//
// 文件说明:Discuz论坛帖子首页调用(菜鸟简洁版)
// --------------------------------------------------------------//
// 程序作者:Spring
// --------------------------------------------------------------//
// 程序主页:http://www.mephp.com
// --------------------------------------------------------------//
// 使用方法:把discuz_js.php放在论坛根目录;再在调用页添加以下JS
// <script src="discuz/discuz_js.php?new=8&post=3&hot=6"></script>
// new=8&post=3&hot=6可以选择你所需要的参数,也可以不要,既可以这样
// new=8或者post=3或者hot=6或者new=8&post=3或者post=3&hot=6
include "config.php";
//==========================变量定义===============================
$titlelength= 20; //标题长度,按字节
$discuz_table = $tablepre."threads";   //discuz表名
$new    = $HTTP_GET_VARS['new']; //最新发表显示标题数
$post     = $HTTP_GET_VARS['post'];//最新回复显示标题数
$hot    = $HTTP_GET_VARS['hot']; //回复最多显示标题数
//===========================字符截取函数(防乱码)=================
function m_substr($str,$start=0,$strlen) {
 for($i=0;$i<$strlen;$i++)
   if(ord(substr($str,$i,1))>0xa0) $j++;
     if($j%2!=0) $strlen++;
     $str=substr($str,0,$strlen);
     return $str;
}
//===========================调用Discuz帖===========================
@mysql_pconnect($dbhost,$dbuser,$dbpw);
@mysql_select_db($dbname);
//论坛最新发表
$result=@mysql_query("SELECT * FROM `$discuz_table` ORDER BY `dateline` DESC LIMIT 0,$new");
while ($row = mysql_fetch_array($result)) {
 $subject=(strlen($row)<=$titlelength)?$row:(m_substr($row,0,$titlelength)."..");
 $date=date("y-m-d",$row);
 $linedate=date("Y-m-d H:i:s",$row);
 $postdate=date("Y-m-d H:i:s",$row);
 $replies=$row;
 $title="$row 发表:$row $linedate";
 //用户可以修改下行自定义输出格式
 $discuz_lastline.="<TR><TD>◇<a href=bbs/viewthread.php?tid=$row title='$title'>$subject</a></TD><TD>$date</TD></TR>";
}
//论坛最后回复
$result=@mysql_query("SELECT * FROM `$discuz_table` ORDER BY `lastpost` DESC LIMIT 0,$post");
while ($row = mysql_fetch_array($result)) {
 $subject=(strlen($row)<=$titlelength)?$row:(m_substr($row,0,$titlelength)."..");
 $date=date("y-m-d",$row);
 $linedate=date("Y-m-d H:i:s",$row);
 $postdate=date("Y-m-d H:i:s",$row);
 $replies=$row;
 $title="$row 发表:$row $linedate 回复:$row $postdate";
 //用户可以修改下行自定义输出格式
 $discuz_lastpost.="<TR><TD>◇<a href=bbs/viewthread.php?tid=$row title='$title'>$subject</a></TD><TD>$date</TD></TR>";
}
//论坛回复最多
$result=@mysql_query("SELECT * FROM `$discuz_table` ORDER BY `replies` DESC LIMIT 0,$hot");
while ($row = mysql_fetch_array($result)) {
 $subject=(strlen($row)<=$titlelength)?$row:(m_substr($row,0,$titlelength)."..");
 $date=date("y-m-d",$row);
 $linedate=date("Y-m-d H:i:s",$row);
 $postdate=date("Y-m-d H:i:s",$row);
 $replies=$row;
 $title="$row 发表:$row $linedate 回复数:$replies";
 //用户可以修改下行自定义输出格式
 $discuz_replies.="<TR><TD>◇<a href=bbs/viewthread.php?tid=$row title='$title'>$subject</a></TD><TD>$date</TD></TR>";
}
//===========================输出调用帖==========================
if(!empty($new)) $list.= "◆ 论坛最新发表<TABLE width=98% cellSpacing=3 cellPadding=0 border=1>$discuz_lastline</TABLE>";
if(!empty($post)) $list .= "◆ 论坛最后回复<TABLE width=98% cellSpacing=3 cellPadding=0 border=1>$discuz_lastpost</TABLE>";
if(!empty($hot)) $list.= "◆ 论坛回复最多<TABLE width=98% cellSpacing=3 cellPadding=0 border=1>$discuz_replies</TABLE>";
echo "document.write(\"$list\");";
?>

也可以点击下载:http://www.mephp.com/data/upfile/discuz_js.rar
查看演示: http://www.mephp.com/bbs.htm
参考:http://www.mephp.com/view.php?id=26

FROM MEPHP

mutou 发表于 2005 年 12 月 18 日 15:25:06

不怎么美观

oghuz 发表于 2005 年 12 月 18 日 13:41:36

Discuz论坛帖子首页调用(菜鸟简洁版)原理

分5步:
1:从数据库找到源数据
2:需要什么数据
3:执行SQL得到数据
4:格式化数据
5:调用JS

1:从数据库找到源数据,在discuz_threads,自己用PHPMYADMIN导出--
-- 表的结构 `discuz_threads`
--

CREATE TABLE `discuz_threads` (
`tid` mediumint(8) unsigned NOT NULL auto_increment,
`fid` smallint(6) unsigned NOT NULL default '0',
`creditsrequire` smallint(6) unsigned NOT NULL default '0',
`iconid` smallint(6) unsigned NOT NULL default '0',
`author` char(15) NOT NULL default '',
`authorid` mediumint(8) unsigned NOT NULL default '0',
`subject` char(80) NOT NULL default '',
`dateline` int(10) unsigned NOT NULL default '0',
`lastpost` int(10) unsigned NOT NULL default '0',
`lastposter` char(15) NOT NULL default '',
`views` mediumint(8) unsigned NOT NULL default '0',
`replies` smallint(6) unsigned NOT NULL default '0',
`displayorder` tinyint(1) NOT NULL default '0',
`highlight` tinyint(1) NOT NULL default '0',
`digest` tinyint(1) NOT NULL default '0',
`blog` tinyint(1) NOT NULL default '0',
`poll` tinyint(1) NOT NULL default '0',
`attachment` tinyint(1) NOT NULL default '0',
`closed` mediumint(8) unsigned NOT NULL default '0',
`threads_moderatetime` char(15) NOT NULL default '',
`threads_moderate` tinyint(1) NOT NULL default '0',
`threads_moderator` char(15) NOT NULL default '',
`threads_moderatorid` char(8) NOT NULL default '',
`authornick` char(15) NOT NULL default '',
PRIMARY KEY(`tid`),
KEY `displayorder` (`fid`,`displayorder`,`lastpost`),
KEY `digest` (`digest`)
) TYPE=MyISAM AUTO_INCREMENT=10 ;

--
-- 导出表中的数据 `discuz_threads`
--

INSERT INTO `discuz_threads` VALUES (1, 4, 0, 0, '懑梵', 5, '晕死', 1128577768, 1128623748, 'macrolong', 42, 9, 0, 0, 0, 0, 0, 0, 0, '1128577768', 0, '懑梵', '5', '');

2:需要什么数据看到了把,帖子的N个属性,这几个是关键的,subject(标题),dateline(发表时间),lastpost(最后回复),replies(回复数),其他一样,很好理解的 ,就要着几个。

3:执行SQL得到数据
$result=@mysql_query("SELECT * FROM `$discuz_table` ORDER BY `lastpost` DESC LIMIT 0,$post");
while ($row = mysql_fetch_array($result)) {
 $subject=(strlen($row)<=$titlelength)?$row:(m_substr($row,0,$titlelength)."..");
 $date=date("y-m-d",$row);
 $linedate=date("Y-m-d H:i:s",$row);
 $postdate=date("Y-m-d H:i:s",$row);
 $views=$row;
}

4:格式化数据
$discuz_lastpost.="<TR><TD>◇<a href=bbs/viewthread.php?tid=$row title='$title'>$subject</a></TD><TD>$date</TD></TR>";

5:调用JS

把discuz_js.php放在论坛根目录;再在调用页添加以下JS:
<script src="discuz/discuz_js.php?new=8&post=3&hot=6"></script>new=8&post=3&hot=6可以选择你所需要的参数,也可以不要,既可以这样:new=8或者post=3或者hot=6或者new=8&post=3或者post=3&hot=6

简单把,其他什么精华贴,置顶贴都相似,有兴趣的可以自己写。希望这编文章对大家有用。
完整的代码如下:
<?php
// ========================== 文件说明 ==========================//
// 文件说明:Discuz论坛帖子首页调用(菜鸟简洁版)
// --------------------------------------------------------------//
// 程序作者:Spring
// --------------------------------------------------------------//
// 程序主页:http://www.mephp.com
// --------------------------------------------------------------//
// 使用方法:把discuz_js.php放在论坛根目录;再在调用页添加以下JS
// <script src="discuz/discuz_js.php?new=8&post=3&hot=6"></script>
// new=8&post=3&hot=6可以选择你所需要的参数,也可以不要,既可以这样
// new=8或者post=3或者hot=6或者new=8&post=3或者post=3&hot=6
include "config.php";
//==========================变量定义===============================
$titlelength= 20; //标题长度,按字节
$discuz_table = $tablepre."threads";   //discuz表名
$new    = $HTTP_GET_VARS['new']; //最新发表显示标题数
$post     = $HTTP_GET_VARS['post'];//最新回复显示标题数
$hot    = $HTTP_GET_VARS['hot']; //回复最多显示标题数
//===========================字符截取函数(防乱码)=================
function m_substr($str,$start=0,$strlen) {
 for($i=0;$i<$strlen;$i++)
   if(ord(substr($str,$i,1))>0xa0) $j++;
     if($j%2!=0) $strlen++;
     $str=substr($str,0,$strlen);
     return $str;
}
//===========================调用Discuz帖===========================
@mysql_pconnect($dbhost,$dbuser,$dbpw);
@mysql_select_db($dbname);
//论坛最新发表
$result=@mysql_query("SELECT * FROM `$discuz_table` ORDER BY `dateline` DESC LIMIT 0,$new");
while ($row = mysql_fetch_array($result)) {
 $subject=(strlen($row)<=$titlelength)?$row:(m_substr($row,0,$titlelength)."..");
 $date=date("y-m-d",$row);
 $linedate=date("Y-m-d H:i:s",$row);
 $postdate=date("Y-m-d H:i:s",$row);
 $replies=$row;
 $title="$row 发表:$row $linedate";
 //用户可以修改下行自定义输出格式
 $discuz_lastline.="<TR><TD>◇<a href=bbs/viewthread.php?tid=$row title='$title'>$subject</a></TD><TD>$date</TD></TR>";
}
//论坛最后回复
$result=@mysql_query("SELECT * FROM `$discuz_table` ORDER BY `lastpost` DESC LIMIT 0,$post");
while ($row = mysql_fetch_array($result)) {
 $subject=(strlen($row)<=$titlelength)?$row:(m_substr($row,0,$titlelength)."..");
 $date=date("y-m-d",$row);
 $linedate=date("Y-m-d H:i:s",$row);
 $postdate=date("Y-m-d H:i:s",$row);
 $replies=$row;
 $title="$row 发表:$row $linedate 回复:$row $postdate";
 //用户可以修改下行自定义输出格式
 $discuz_lastpost.="<TR><TD>◇<a href=bbs/viewthread.php?tid=$row title='$title'>$subject</a></TD><TD>$date</TD></TR>";
}
//论坛回复最多
$result=@mysql_query("SELECT * FROM `$discuz_table` ORDER BY `replies` DESC LIMIT 0,$hot");
while ($row = mysql_fetch_array($result)) {
 $subject=(strlen($row)<=$titlelength)?$row:(m_substr($row,0,$titlelength)."..");
 $date=date("y-m-d",$row);
 $linedate=date("Y-m-d H:i:s",$row);
 $postdate=date("Y-m-d H:i:s",$row);
 $replies=$row;
 $title="$row 发表:$row $linedate 回复数:$replies";
 //用户可以修改下行自定义输出格式
 $discuz_replies.="<TR><TD>◇<a href=bbs/viewthread.php?tid=$row title='$title'>$subject</a></TD><TD>$date</TD></TR>";
}
//===========================输出调用帖==========================
if(!empty($new)) $list.= "◆ 论坛最新发表<TABLE width=98% cellSpacing=3 cellPadding=0 border=1>$discuz_lastline</TABLE>";
if(!empty($post)) $list .= "◆ 论坛最后回复<TABLE width=98% cellSpacing=3 cellPadding=0 border=1>$discuz_lastpost</TABLE>";
if(!empty($hot)) $list.= "◆ 论坛回复最多<TABLE width=98% cellSpacing=3 cellPadding=0 border=1>$discuz_replies</TABLE>";
echo "document.write(\"$list\");";
?>

也可以点击下载:http://www.mephp.com/data/upfile/discuz_js.rar
查看演示: http://www.mephp.com/bbs.htm
参考:http://www.mephp.com/view.php?id=26

FROM MEPHP
页: [1]
查看完整版本: Discuz论坛帖子首页调用(菜鸟简洁版)原理