欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

树状BBS设计参考_PHP

程序员文章站 2022-03-11 11:45:11
...
简单 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)
);



This is my BBS



/******************************************************
BBS v1.0
编码: PHP 3
作者: Leon Atkinson

简单 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( "

Leon's BBS

\n");

/* 设置数据库 */
mysql_pconnect( "www.yoursever.com", "httpd");
$Database = "yourdb";

/****************************************************************
一个吐出派生信息的递归函数
****************************************************************/
function showMessages($parentID)
{
global $Database;

$dateToUse = Date( "U");

echo "

    \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 {
    $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( "

  • ($messageCreated) $messageTitle
    \n");

    /* 调用 getWingContents 以得到它的分支 */
    showMessages($messageID);

    $RowCount++;
    }

    echo "

\n";
}

/****************************************************************
输出一个提交新信息的表单,并在其中预置一个父ID
****************************************************************/
function postForm($parentID, $useTitle)
{
printf( "

\n");
printf( "");
printf( "");
printf( "\n");
printf( "");
printf( "\n");
printf( "");
printf( "\n");
printf( "\n");
printf( "\n");
printf( "
Title
Poster
");
printf( "
\n");
printf( "
\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 {
$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( "

\n");
printf( "\n");
printf( "\n");
printf( "\n");
printf( "\n");
printf( "
Title $messageTitle
Poster $messagePoster
Posted $messageCreated
$messageBody
\n");

postForm($messageID, "RE: $messageTitle");

}

echo "List of Messages
";

}
else
{
printf( "

List of Messages

\n");

/* 调用递归函数*/
showMessages(0);

postForm(0, "");

}

?>