Discussion Board Code

  Home arrow Discussion Board Code arrow TinyBoard 1.2
DISCUSSION BOARD CODE

TinyBoard 1.2
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2002-01-18

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    Simple message board working on MySQL database. It supports multiple levels, threads, search by topic or free text. SQL part is made up using PHPLib. Zip file includes a working example and images for toolbars. http://members.xoom.it/fathom/TinyBoard-1.2.zip

    By : fath

    <?
    /******************************************************************************************
    * TinyBoard 1.2 *
    * by Francesco Toscan, fathom@unixlover.com *
    * Included classes: PHPLib *
    * This code is released under GPL license *
    ******************************************************************************************/

    $board_tbl_questions = "board_questions";
    $board_tbl_answers = "board_answers";

    function BoardToolsFull ($ID,$Depth,$FormerID) {
    global $PHP_SELF, $type;
    require("modules/board-toolsfull.html");
    }

    function BoardToolsPartial () {
    global $PHP_SELF;
    require("modules/board-toolspartial.html");
    }

    function BoardFooter () {
    require("modules/board-footer.html");
    }

    /* Let's simply list messages in questions table and check whether there are replies */
    function BoardIndex () {
    global $db, $PHP_SELF, $board_tbl_questions, $board_tbl_answers;
    $db->query("SELECT ID,Sender,Date,Topic,NumMsgs from $board_tbl_questions order by Date;");
    $numrows = $db->num_rows();
    if ($numrows != 0) {
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#000000\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\">";
    echo "<tr><td>\n";
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#e6e6e6\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
    echo "<tr>\n";
    echo "<th bgcolor=\"#333399\" width=\"60%\"><font size=\"-1\" color=\"#FFFFFF\">Topic</font>\n";
    echo "</th>\n";
    echo "<th bgcolor=\"#333399\" width=\"20%\"><font color=\"#FFFFFF\" size=\"-1\">Sender</font></th>\n";
    echo "<th bgcolor=\"#333399\"><font color=\"#FFFFFF\" size=\"-1\">Date</font></th>\n";
    echo "</tr>\n";
    while ($db->next_record()) {
    $ID = $db->f(ID);
    $Sender = $db->f(Sender);
    $Date = $db->f(Date);
    $Topic = $db->f(Topic);
    echo "<tr>\n";
    echo "<td width=\"60%\"><font size=\"-2\">\n";
    if ($db->f(NumMsgs) > 0) {
    echo "<a href=\"$PHP_SELF?action=expand_thread&ID=$ID\"><img src=\"pics/plus.gif\" border=\"0\" valign=\"middle\"></a> ";
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=question\">$Topic</a></font></td>\n";
    }
    else {
    echo "<img src=\"pics/stateful.gif\" border=\"0\"> ";
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=question\">$Topic</a></font></td>\n";
    }
    echo "<td width=\"20%\" align=\"center\"><font size=\"-2\">$Sender</font></td>\n";
    echo "<td align=\"center\"><font size=\"-2\">$Date</font></td>\n";
    echo "</tr>\n";
    }
    echo "</table>\n";
    echo "</td></tr></table>\n";
    }
    else {
    echo "No message found.\n";
    }
    BoardFooter();
    }

    /* We want to add messages */
    function BoardAddNewMsg() {
    global $db, $CodSede, $Sender, $Text, $Topic, $PHP_SELF, $board_tbl_questions, $board_tbl_answers;
    /* Let's make an unique ID for each message. */
    $ID = uniqid(rand(),true);
    $Date = date("Y/m/d");
    /* Check whether ID is really unique */
    $db->query("SELECT ID from $board_tbl_questions where ID=\"$ID\";");
    $numrows = $db->num_rows();
    if ($numrows != 0) {
    while ($numrows != 0) {
    $ID = uniqid(rand(),true);
    $numrows = $db->num_rows();
    }
    }
    /* Insert query */
    $query = "INSERT INTO $board_tbl_questions SET ID=\"$ID\",Sender=\"$CodSede\",Date=\"$Date\",Text=\"$Text\",Topic=\"$Topic\";";
    if ($db->query($query)) {
    echo "<center>Message sent.<br>\n";
    echo "<a href=\"$PHP_SELF\">Back</a></center>\n";
    }
    else {
    echo "Problem has occurred while sending message. Send failed.\n";
    }
    BoardFooter();
    }

    /* Expanding threads by question ID */
    function BoardThreadExpand($ID,$maxDepth) {
    global $db, $PHP_SELF, $board_tbl_questions, $board_tbl_answers;
    /* First of all the former message */
    if ($maxDepth == 1) {
    $db->query("SELECT ID,Sender,Date,Topic from $board_tbl_questions where ID=\"$ID\";");
    }
    else {
    $db->query("SELECT ID,Sender,Date,Topic from $board_tbl_answers where ID=\"$ID\";");
    }
    $db->next_record();
    $Sender = $db->f(Sender);
    $Date = $db->f(Date);
    $Topic = $db->f(Topic);
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#000000\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\">";
    echo "<tr><td>\n";
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#e6e6e6\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
    echo "<tr>\n";
    echo "<th bgcolor=\"#333399\" width=\"60%\"><font size=\"-1\" color=\"#FFFFFF\">Topic</font>\n";
    echo "</th>\n";
    echo "<th bgcolor=\"#333399\" width=\"20%\"><font color=\"#FFFFFF\" size=\"-1\">Sender</font></th>\n";
    echo "<th bgcolor=\"#333399\"><font color=\"#FFFFFF\" size=\"-1\">Date</font></th>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td width=\"60%\"><font size=\"-2\">\n";
    echo "<a href=\"javascript: history.back(-1)\">";
    echo "<img src=\"pics/minus.gif\" border=\"0\" valign=\"middle\"></a> ";
    if ($maxDepth == 1) {
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=question\">$Topic</a></font></td>\n";
    }
    else {
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=answer\">$Topic</a></font></td>\n";
    }
    echo "<td width=\"20%\" align=\"center\"><font size=\"-2\">$Sender</font></td>\n";
    echo "<td align=\"center\"><font size=\"-2\">$Date</font></td>\n";
    echo "</tr>\n";
    /* List all messages matching thread ID */
    $query = "SELECT ID,Sender,Date,Topic,Depth,NumMsgs from $board_tbl_answers where FormerID=\"$ID\" OR OrigID=\"$ID\";";
    $db->query($query);
    $numMsgs = $db->num_rows();
    while ($db->next_record()) {
    if ($db->f(Depth) == $maxDepth) {
    $ID = $db->f(ID);
    $Sender = $db->f(Sender);
    $Date = $db->f(Date);
    $Topic = $db->f(Topic);
    $Depth = $db->f(Depth);
    echo "<tr>\n";
    echo "<td width=\"60%\"><font size=\"-2\">\n";
    if ($db->f(NumMsgs) > 0) {
    $newDepth = $Depth +1;
    echo "<a href=\"$PHP_SELF?action=expand_thread&ID=$ID&maxDepth=$newDepth\"><img src=\"pics/plus.gif\" border=\"0\" valign=\"middle\"></a> ";
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=answer\">$Topic</a></font></td>\n";
    }
    else {
    echo "<img src=\"pics/node.gif\" border=\"0\"> ";
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=answer\">$Topic</a></font></td>\n";
    }
    echo "<td width=\"20%\" align=\"center\"><font size=\"-2\">$Sender</font></td>\n";
    echo "<td align=\"center\"><font size=\"-2\">$Date</font></td>\n";
    echo "</tr>\n";
    }
    }
    echo "</table>\n";
    echo "</td></tr></table>\n";
    echo "<br>\n";
    echo "<font size=\"-2\">Level <b>$maxDepth</b></font>\n";
    BoardFooter();
    }

    function BoardShowMsg ($ID,$type) {
    global $db, $PHP_SELF, $board_tbl_questions, $board_tbl_answers;
    if ($type == "question") {
    $query = "SELECT ID,Sender,Topic,Date,Text from $board_tbl_questions where ID=\"$ID\";";
    }
    else {
    $query = "SELECT ID,Sender,Topic,Date,Text,FormerID,Depth from $board_tbl_answers where ID=\"$ID\";";
    }
    $db->query($query);
    $numrows = $db->num_rows();
    if ($numrows > 0) {
    $db->next_record();
    $Sender = $db->f(Sender);
    $Topic = $db->f(Topic);
    $Date = $db->f(Date);
    $Text = $db->f(Text);
    $FormerID = $db->f(FormerID);
    $Depth = $db->f(Depth);
    BoardToolsFull($ID,$Depth,$FormerID);
    require("modules/board-show.html");
    }
    else {
    echo "Message ID $ID not found.\n";
    }
    BoardFooter();
    }

    function BoardNewMsg () {
    require("modules/board-newmsg.html");
    }

    function BoardAddReply ($ID) {
    global $PHP_SELF, $db, $type, $Depth, $Sender, $Text, $Topic, $FormerID, $board_tbl_questions, $board_tbl_answers;
    $newID = uniqid(rand(),true);
    $Date = date("Y/m/d");
    if ($type == "question") {
    $query = "INSERT INTO $board_tbl_answers SET ID=\"$newID\",OrigID=\"$ID\",FormerID=\"$ID\",Depth=\"1\",Sender=\"$Sender\",Date=\"$Date\",Topic=\"$Topic\",Text=\"$Text\";";
    $db->query($query);
    $update = "UPDATE $board_tbl_questions SET NumMsgs=NumMsgs +1 WHERE ID=\"$ID\";";
    $db->query($update);
    echo "<center>Message sent.<br>\n";
    echo "<a href=\"$PHP_SELF\">Back</a></center>\n";
    }
    else {
    $Depth = $Depth +1;
    $query = "INSERT INTO $board_tbl_answers SET ID=\"$newID\",OrigID=\"$ID\",FormerID=\"$FormerID\",Depth=\"$Depth\",Sender=\"$Sender\",Date=\"$Date\",Topic=\"$Topic\",Text=\"$Text\";";
    $db->query($query);
    $update = "UPDATE $board_tbl_answers SET NumMsgs=NumMsgs +1 WHERE ID=\"$ID\";";
    $db->query($update);
    echo "<center>Message sent.<br>\n";
    echo "<a href=\"$PHP_SELF\">Back</a></center>\n";
    }
    BoardFooter();
    }

    function BoardReplyMsg($ID) {
    global $PHP_SELF, $db, $FormerID, $Depth, $type, $CodSede, $board_tbl_questions, $board_tbl_answers;
    if ($type == "question") {
    $query = "SELECT Sender,Topic,Date,Text from $board_tbl_questions where ID=\"$ID\";";
    }
    else {
    $query = "SELECT Sender,Topic,Date,Text from $board_tbl_answers where ID=\"$ID\";";
    }
    $db->query($query);
    $numrows = $db->num_rows();
    if ($numrows > 0) {
    $db->next_record();
    $Sender = $db->f(Sender);
    $Topic = $db->f(Topic);
    $Date = $db->f(Date);
    $Text = $db->f(Text);
    }
    BoardToolsPartial();
    require("modules/board-replymsg.html");
    BoardFooter();
    }

    function BoardPerformSearch ($what) {
    global $PHP_SELF, $db, $Topic, $Text, $board_tbl_questions, $board_tbl_answers;
    $found = 0;
    switch ($what) {
    case topic:
    $query = "SELECT ID,Sender,Topic,Date,NumMsgs from $board_tbl_questions WHERE Topic LIKE \"%$Topic%\";";
    $db->query($query);
    echo "<h4>Search results</h4>\n";
    BoardToolsPartial();
    if ($db->num_rows() > 0) {
    $found++;
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#000000\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\">";
    echo "<tr><td>\n";
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#e6e6e6\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
    echo "<tr>\n";
    echo "<th bgcolor=\"#333399\" width=\"60%\"><font size=\"-1\" color=\"#FFFFFF\">Topic</font>\n";
    echo "</th>\n";
    echo "<th bgcolor=\"#333399\" width=\"20%\"><font color=\"#FFFFFF\" size=\"-1\">Sender</font></th>\n";
    echo "<th bgcolor=\"#333399\"><font color=\"#FFFFFF\" size=\"-1\">Date</font></th>\n";
    echo "</tr>\n";
    while ($db->next_record()) {
    $ID = $db->f(ID);
    $Sender = $db->f(Sender);
    $Date = $db->f(Date);
    $Topic = $db->f(Topic);
    echo "<tr>\n";
    echo "<td width=\"60%\"><font size=\"-2\">\n";
    if ($db->f(NumMsgs) > 0) {
    echo "<a href=\"$PHP_SELF?action=expand_thread&ID=$ID\"><img src=\"pics/plus.gif\" border=\"0\" valign=\"middle\"></a> ";
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=question\">$Topic</a></font></td>\n";
    }
    else {
    echo "<img src=\"pics/stateful.gif\" border=\"0\"> ";
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=question\">$Topic</a></font></td>\n";
    }
    echo "<td width=\"20%\" align=\"center\"><font size=\"-2\">$Sender</font></td>\n";
    echo "<td align=\"center\"><font size=\"-2\">$Date</font></td>\n";
    echo "</tr>\n";
    }
    echo "</table>\n";
    echo "</td></tr></table>\n";
    }
    else {
    echo "No message found.\n";
    }
    break;

    case text:
    $query = "SELECT ID,Topic,Sender,Date,NumMsgs from $board_tbl_questions WHERE Text LIKE \"%$Text%\";";
    $db->query($query);
    echo "<h4>Search results</h4>\n";
    BoardToolsPartial();
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#000000\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\">";
    echo "<tr><td>\n";
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#e6e6e6\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
    echo "<tr>\n";
    echo "<th bgcolor=\"#333399\" width=\"60%\"><font size=\"-1\" color=\"#FFFFFF\">Topic</font>\n";
    echo "</th>\n";
    echo "<th bgcolor=\"#333399\" width=\"20%\"><font color=\"#FFFFFF\" size=\"-1\">Sender</font></th>\n";
    echo "<th bgcolor=\"#333399\"><font color=\"#FFFFFF\" size=\"-1\">Date</font></th>\n";
    echo "</tr>\n";
    if ($db->num_rows() > 0) {
    $found++;
    while ($db->next_record()) {
    $ID = $db->f(ID);
    $Sender = $db->f(Sender);
    $Date = $db->f(Date);
    $Topic = $db->f(Topic);
    echo "<tr>\n";
    echo "<td width=\"60%\"><font size=\"-2\">\n";
    echo "<img src=\"pics/stateful.gif\" border=\"0\"> ";
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=question\">$Topic</a></font></td>\n";
    echo "<td width=\"20%\" align=\"center\"><font size=\"-2\">$Sender</font></td>\n";
    echo "<td align=\"center\"><font size=\"-2\">$Date</font></td>\n";
    echo "</tr>\n";
    }
    echo "</table>\n";
    echo "</td></tr></table>\n";
    }
    $query = "SELECT ID,Topic,Sender,Date,Depth,NumMsgs from $board_tbl_answers WHERE Text LIKE \"%$Text%\";";
    $db->query($query);
    if ($db->num_rows() > 0) {
    $found++;
    while ($db->next_record()) {
    $ID = $db->f(ID);
    $Sender = $db->f(Sender);
    $Date = $db->f(Date);
    $Topic = $db->f(Topic);
    $Depth = $db->f(Depth);
    echo "<tr>\n";
    echo "<td width=\"60%\"><font size=\"-2\">\n";
    echo "<img src=\"pics/stateful.gif\" border=\"0\"> ";
    echo "<a href=\"$PHP_SELF?action=show_msg&ID=$ID&type=answer\">$Topic</a></font></td>\n";
    echo "<td width=\"20%\" align=\"center\"><font size=\"-2\">$Sender</font></td>\n";
    echo "<td align=\"center\"><font size=\"-2\">$Date</font></td>\n";
    echo "</tr>\n";
    }
    echo "</table>\n";
    /* if ($found == "0") {
    echo "<table width=\"100%\" border=\"0\" bgcolor=\"#e6e6e6\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
    echo "<tr><td align=\"center\">No message found</td></tr></table>\n";
    } */
    echo "</td></tr></table>\n";
    }
    break;

    default:
    echo "Missing search key.\n";
    break;
    }
    BoardFooter();
    }

    function BoardSearchMsg() {
    global $PHP_SELF, $board_tbl_questions, $board_tbl_answers;
    require("modules/board-searchmsg.html");
    BoardFooter();
    }

    /* Use at your own risk :)) */
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Discussion Board Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    DISCUSSION BOARD CODE ARTICLES

    - phpBB Google Sitemap XML generator v2.1
    - myPHPWiKi
    - Simple Shoutbox 1.3
    - Chipmunk Board
    - TagIt! Tagboard v2.1.B Build 2 - UPDATED 11....
    - Internal Mail System
    - phpAdBoard
    - Super Simple Discussion 4 sysadmins
    - Powerbox Version 0.2
    - SXMB
    - J.A.G. (Just Another Guestbook)
    - PowerBox
    - TagIt! Tagboard
    - Tom's Corkboard
    - MiniChat


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap