树状BBS设计参考
时间:2007-02-17 来源:PHP爱好者
简单 BBS 系统 需 MySQL。
以下是BBS的表结构,用以下的语句就可以建立: CREATE TABLE bbsMessage
(
ID INT NOT NULL AUTO_INCREMENT,
Title VARCHAR(64),
Poster VARCHAR(64),
Created DATETIME,
Parent INT,
Body BLOB,
PRIMARY KEY(ID)
); <HTML>
<HEAD>
<TITLE>This is my BBS</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?
/******************************************************
BBS v1.0
编码: PHP 3
作者: Leon Atkinson <[email protected] >
简单 BBS 系统 需 MySQL。
以下是BBS的表结构,用以下的语句就可以建立: CREATE TABLE bbsMessage
(
ID INT NOT NULL AUTO_INCREMENT,
Title VARCHAR(64),
Poster VARCHAR(64),
Created DATETIME,
Parent INT,
Body BLOB,
PRIMARY KEY(ID)
); *******************************************************/ printf( "<H1>Leon's BBS</H1>n"); /* 设置数据库 */
mysql_pconnect( "www.yoursever.com", "httpd");
$Database = "yourdb"; /****************************************************************
一个吐出派生信息的递归函数
****************************************************************/
function showMessages($parentID)
{
global $Database; $dateToUse = Date( "U"); echo "<UL>n"; /* 显示所有的类别 */
$Query = "SELECT * FROM bbsMessage ";
$Query = $Query . "WHERE Parent=$parentID ";
$Query = $Query . "ORDER BY Created "; $result = mysql($Database,$Query);
$numRows = mysql_NumRows($result);
$RowCount = 0;
while($RowCount <$numRows)
{
$messageID = mysql_result($result,$RowCount, "ID");
$messageTitle = mysql_result($result,$RowCount, "Title");
$messageCreated = mysql_result($result,$RowCount, "Created");
$messageParent = mysql_result($result,$RowCount, "Parent"); /*显示一行是什么类别的信息 */
printf( "<LI>($messageCreated) <A HREF="bbs.htma?messageID=$messageID">$messageTitle</A><BR>n");
/* 调用 getWingContents 以得到它的分支 */
showMessages($messageID); $RowCount++;
} echo "</UL>n";
} /****************************************************************
输出一个提交新信息的表单,并在其中预置一个父ID
****************************************************************/
function postForm($parentID, $useTitle)
{
printf( "<FORM ACTION="bbs.htma" METHOD="post">n");
printf( "<INPUT TYPE="hidden" NAME="inputParent" VALUE="$parentID">");
printf( "<INPUT TYPE="hidden" NAME="ACTION" VALUE="POST">");
printf( "<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5" WIDTH="400">n");
printf( "<TR><TD WIDTH="100"><B>Title</B></TD>");
printf( "<TD WIDTH="300"><INPUT TYPE="text" NAME="inputTitle" SIZE="35" MAXLENGTH"64" VALUE="$useTitle"></TD></TR>n");
printf( "<TR><TD WIDTH="100"><B>Poster</B></TD>");
printf( "<TD WIDTH="300"><INPUT TYPE="text" NAME="inputPoster" SIZE="35" MAXLENGTH"64"></TD></TR>n");
printf( "<TR><TD COLSPAN="2" WIDTH="400">");
printf( "<TEXTAREA NAME="inputBody" COLS="45" ROWS="5"></TEXTAREA></TD></TR>n");
printf( "<TR><TD COLSPAN="2" WIDTH="400"><CENTER><INPUT TYPE="submit" VALUE="Post"></CENTER></TD></TR>n");
printf( "</TABLE>n");
printf( "</FORM>n"); } /******************************************************
执行动作
******************************************************/
if($ACTION != "")
{
if($ACTION == "POST")
{
$inputTitle = ereg_replace( "'", "''", $inputTitle);
$inputBody = ereg_replace( "'", "''", $inputBody); $Query = "INSERT INTO bbsMessage ";
$Query .= "VALUES(0, '$inputTitle', ";
$Query .= "'$inputPoster', ";
$Query .= "now(), $inputParent, ";
$Query .= "'$inputBody')";
$result = mysql($Database,$Query);
} }
/******************************************************
显示信息或者是显示信息列表
******************************************************/
if($messageID > 0)
{
$Query = "SELECT * FROM bbsMessage ";
$Query = $Query . "WHERE ID=$messageID "; $result = mysql($Database,$Query);
$numRows = mysql_NumRows($result);
$RowCount = 0;
if($RowCount <$numRows)
{
$messageID = mysql_result($result,$RowCount, "ID");
$messageTitle = mysql_result($result,$RowCount, "Title");
$messagePoster = mysql_result($result,$RowCount, "Poster");
$messageCreated = mysql_result($result,$RowCount, "Created");
$messageParent = mysql_result($result,$RowCount, "Parent");
$messageBody = mysql_result($result,$RowCount, "Body"); printf( "<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5" WIDTH="400">n");
printf( "<TR><TD WIDTH="100"><B>Title</B></TD><TD WIDTH="300">$messageTitle</TD></TR>n");
printf( "<TR><TD WIDTH="100"><B>Poster</B></TD><TD WIDTH="300">$messagePoster</TD></TR>n");
printf( "<TR><TD WIDTH="100"><B>Posted</B></TD><TD WIDTH="300">$messageCreated</TD></TR>n");
printf( "<TR><TD COLSPAN="2" WIDTH="400">$messageBody</TD></TR>n");
printf( "</TABLE>n"); postForm($messageID, "RE: $messageTitle"); }
echo "<A HREF="bbs.htma">List of Messages</A><BR>"; }
else
{
printf( "<H2>List of Messages</H2>n"); /* 调用递归函数*/
showMessages(0); postForm(0, ""); } ?> </BODY>
</HTML>
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
以下是BBS的表结构,用以下的语句就可以建立: CREATE TABLE bbsMessage
(
ID INT NOT NULL AUTO_INCREMENT,
Title VARCHAR(64),
Poster VARCHAR(64),
Created DATETIME,
Parent INT,
Body BLOB,
PRIMARY KEY(ID)
); <HTML>
<HEAD>
<TITLE>This is my BBS</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?
/******************************************************
BBS v1.0
编码: PHP 3
作者: Leon Atkinson <[email protected] >
简单 BBS 系统 需 MySQL。
以下是BBS的表结构,用以下的语句就可以建立: CREATE TABLE bbsMessage
(
ID INT NOT NULL AUTO_INCREMENT,
Title VARCHAR(64),
Poster VARCHAR(64),
Created DATETIME,
Parent INT,
Body BLOB,
PRIMARY KEY(ID)
); *******************************************************/ printf( "<H1>Leon's BBS</H1>n"); /* 设置数据库 */
mysql_pconnect( "www.yoursever.com", "httpd");
$Database = "yourdb"; /****************************************************************
一个吐出派生信息的递归函数
****************************************************************/
function showMessages($parentID)
{
global $Database; $dateToUse = Date( "U"); echo "<UL>n"; /* 显示所有的类别 */
$Query = "SELECT * FROM bbsMessage ";
$Query = $Query . "WHERE Parent=$parentID ";
$Query = $Query . "ORDER BY Created "; $result = mysql($Database,$Query);
$numRows = mysql_NumRows($result);
$RowCount = 0;
while($RowCount <$numRows)
{
$messageID = mysql_result($result,$RowCount, "ID");
$messageTitle = mysql_result($result,$RowCount, "Title");
$messageCreated = mysql_result($result,$RowCount, "Created");
$messageParent = mysql_result($result,$RowCount, "Parent"); /*显示一行是什么类别的信息 */
printf( "<LI>($messageCreated) <A HREF="bbs.htma?messageID=$messageID">$messageTitle</A><BR>n");
/* 调用 getWingContents 以得到它的分支 */
showMessages($messageID); $RowCount++;
} echo "</UL>n";
} /****************************************************************
输出一个提交新信息的表单,并在其中预置一个父ID
****************************************************************/
function postForm($parentID, $useTitle)
{
printf( "<FORM ACTION="bbs.htma" METHOD="post">n");
printf( "<INPUT TYPE="hidden" NAME="inputParent" VALUE="$parentID">");
printf( "<INPUT TYPE="hidden" NAME="ACTION" VALUE="POST">");
printf( "<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5" WIDTH="400">n");
printf( "<TR><TD WIDTH="100"><B>Title</B></TD>");
printf( "<TD WIDTH="300"><INPUT TYPE="text" NAME="inputTitle" SIZE="35" MAXLENGTH"64" VALUE="$useTitle"></TD></TR>n");
printf( "<TR><TD WIDTH="100"><B>Poster</B></TD>");
printf( "<TD WIDTH="300"><INPUT TYPE="text" NAME="inputPoster" SIZE="35" MAXLENGTH"64"></TD></TR>n");
printf( "<TR><TD COLSPAN="2" WIDTH="400">");
printf( "<TEXTAREA NAME="inputBody" COLS="45" ROWS="5"></TEXTAREA></TD></TR>n");
printf( "<TR><TD COLSPAN="2" WIDTH="400"><CENTER><INPUT TYPE="submit" VALUE="Post"></CENTER></TD></TR>n");
printf( "</TABLE>n");
printf( "</FORM>n"); } /******************************************************
执行动作
******************************************************/
if($ACTION != "")
{
if($ACTION == "POST")
{
$inputTitle = ereg_replace( "'", "''", $inputTitle);
$inputBody = ereg_replace( "'", "''", $inputBody); $Query = "INSERT INTO bbsMessage ";
$Query .= "VALUES(0, '$inputTitle', ";
$Query .= "'$inputPoster', ";
$Query .= "now(), $inputParent, ";
$Query .= "'$inputBody')";
$result = mysql($Database,$Query);
} }
/******************************************************
显示信息或者是显示信息列表
******************************************************/
if($messageID > 0)
{
$Query = "SELECT * FROM bbsMessage ";
$Query = $Query . "WHERE ID=$messageID "; $result = mysql($Database,$Query);
$numRows = mysql_NumRows($result);
$RowCount = 0;
if($RowCount <$numRows)
{
$messageID = mysql_result($result,$RowCount, "ID");
$messageTitle = mysql_result($result,$RowCount, "Title");
$messagePoster = mysql_result($result,$RowCount, "Poster");
$messageCreated = mysql_result($result,$RowCount, "Created");
$messageParent = mysql_result($result,$RowCount, "Parent");
$messageBody = mysql_result($result,$RowCount, "Body"); printf( "<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5" WIDTH="400">n");
printf( "<TR><TD WIDTH="100"><B>Title</B></TD><TD WIDTH="300">$messageTitle</TD></TR>n");
printf( "<TR><TD WIDTH="100"><B>Poster</B></TD><TD WIDTH="300">$messagePoster</TD></TR>n");
printf( "<TR><TD WIDTH="100"><B>Posted</B></TD><TD WIDTH="300">$messageCreated</TD></TR>n");
printf( "<TR><TD COLSPAN="2" WIDTH="400">$messageBody</TD></TR>n");
printf( "</TABLE>n"); postForm($messageID, "RE: $messageTitle"); }
echo "<A HREF="bbs.htma">List of Messages</A><BR>"; }
else
{
printf( "<H2>List of Messages</H2>n"); /* 调用递归函数*/
showMessages(0); postForm(0, ""); } ?> </BODY>
</HTML>
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
相关阅读 更多 +