首页 >后端开发 >php教程 >树状BBS设计参考_PHP

树状BBS设计参考_PHP

WBOY
WBOY原创
2016-06-01 12:34:571216浏览

简单 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,  "");

    }

?>


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn