这是个简单实用的框架式树型论坛,效果请参考:
http://teaman.oso.com.cn/teabbs/
共三个文件,index.html ,list.php, teamanbbs.php
#以下为表结构,字段长度可能定的不太合理,请自行修改
# MySQL dump 7.1
#
# Host: localhost Database: teamanbbs
#--------------------------------------------------------
# Server version 3.22.32-shareware-debug
#
# Table structure for table 'teamanbbs'
#
CREATE TABLE teamanbbs (
id int(10) unsigned DEFAULT '0' NOT NULL auto_increment,//帖子序号
pid int(10) unsigned DEFAULT '0' NOT NULL, //发表的新帖号,缺省为0,在列出所有帖子时用
author varchar(200) binary,
date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
rec smallint(5) unsigned DEFAULT '0' NOT NULL, //用于是否有回复帖的判断,如3个回复就为3
ip varchar(20) binary,
email varchar(200) binary,
homepage varchar(250) binary,
title varchar(250) binary DEFAULT '' NOT NULL,
mote tinyint(3) unsigned DEFAULT '1' NOT NULL, //表情代号
msg text,//正文用
rid int(10) unsigned DEFAULT '0' NOT NULL, //主要用于相关帖子用,就是在回复10号帖时,它就为10
clicks int(5) unsigned DEFAULT '0',
PRIMARY KEY (id),
KEY id (id)
);
下面为主框架文件index.html
<html>
<head>
<title>teaman留言讨论区</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<frameset rows="253,194*" frameborder="YES" border="1" framespacing="1" cols="*" bordercolor="#CCFFCC">
<frame name="list" scrolling="auto" noresize src="list.php" >
<frame name="teamanbbs" src="teamanbbs.php">
</frameset>
<noframes><body bgcolor="#FFFFFF">
您的浏览器不支持框架结构,请点此 <a href="http://teaman.top263.net">Home of teaman</a>.
</body></noframes>
</html>
<?php
//以下为论坛主题列表程序:list.php
mysql_pconnect('localhost','teaman','sex') OR die ("不能连接数据库");
@mysql_select_db("teaman") OR die ("连接数据库失败");
$limit=10;
//计算页数和设定上页、下页
$sql="select count(*) as count from teamanbbs where pid=0"; //pid为0是说明发的新贴而不是回复帖
$result=mysql_query($sql);
$count=mysql_result($result,0,"count");
$allpages=ceil($count/$limit); //取得页数
if ($page<1) $page=1;
if ($page>$allpages) $page=$allpages;
$prepage=$page-1;
$nextpage=$page+1;
$prepage=($prepage<1) ? 1 : $prepage; //如果上一页小于1,则为1,否则为上一页
if ($nextpage>$allpages) $nextpage=$allpages;
$offset=($page-1)*$limit;
$sql="select count(*) as allcount from teamanbbs where id is not null";//用于提取总留言数
mysql_select_db("teaman");
$results=mysql_query($sql);
$allcount=mysql_result($results,0,"allcount");
function listmsg($parent,$off,$lim) { //递归显示帖子的函数
global $php_self,$page;
$sql="select id,pid,author,title,date,msg,mote,rec,rid,clicks from teamanbbs where pid=$parent order by id desc limit $off,$lim";
$result=mysql_query($sql);
echo "<ul>";
while (list($id,$pid,$author,$title,$date,$msg,$mote,$rec,$rid,$clicks) = mysql_fetch_row($result)) {
$author=stripslashes($author);
$author=htmlspecialchars($author);
$title=stripslashes($title);
$title=htmlspecialchars($title);
echo "<li><img src='img/mood".$mote.".gif' width='20' height='20'>";
if ($id!=$theid) echo "<a href='teamanbbs.php?cid=show&page=".$page."&theid=".$id."' target='teamanbbs'>"; else echo "<b>";
echo $title;
if ($id!=$theid) echo "</a>"; else echo "</b>";
if($email!="") echo "<a href='mailto:".$email."'>";
echo "<b>---".$author." </b>";
if ($email!="") echo "</a>";
echo $date."[点击:".$clicks."]";
if ($msg=="") echo "(无内容)</li>"; else echo "(".strlen($msg)."字)</li>";
if ($rec>0) listmsg($id,0,20); //看是否还有跟帖,发帖的时候判断是跟还是新
}
echo "</ul>";
}
function howpage() { //分页的函数,放在一个函数里,方便调用
global $page,$php_self,$prepage,$nextpage,$allpages,$allcount;
echo "Teaman留言区 ";
if ($page!=1) echo "<a href='".$php_self."?cid=list&page=1'>";
echo "首页";
if ($page!=1) echo "</a> ";
if ($page>1) echo "<a href='".$php_self."?cid=list&page=$prepage'>";
echo "上一页";
if ($page>1) echo "</a> ";
if ($page<$allpages) echo "<a href='".$php_self."?cid=list&page=$nextpage'>";
echo "下一页";
if ($page<$allpages) echo "</a> ";
if ($page!=$allpages) echo "<a href='".$php_self."?cid=list&page=$allpages'>"; echo "末页</a> ";
echo "<a href='".$php_self."?cid=list'>刷新</a> ";
echo "<a href='teamanbbs.php?cid=addnew' target='teamanbbs'>发表留言</a> ";
echo "总留言数:".$allcount." ";
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="teamancss/bbs.css">
<style type="text/css">
<!--
body { font-family: "Arial", "Helvetica", "sans-serif", "Arial Narrow"; font-size: 9pt; background-attachment: fixed; background-image: url(img/back.gif)}
-->
</style>
</head>
<body bgcolor="#FFFFFF">
<table width="750" border="0" cellspacing="1" cellpadding="1" class="p9">
<tr>
<td><?php howpage() ?>//这里开始调用分页函数
<hr size="1" width="745" align="center">
</td>
</tr>
</table>
<table width="750" border="0" cellspacing="1" cellpadding="1">
<tr> </tr>
<tr>
<td><span class="p9"><?php listmsg(0,$offset,$limit); //这里就调用显示帖子 ?></span></td>
</tr>
</table>
<br>
</body>
</html>
|