PHP
  Home arrow PHP arrow Page 2 - Developing a Discussion Forum in PHP with Recursion
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Developing a Discussion Forum in PHP with Recursion
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 12
    2006-05-15


    Table of Contents:
  • Developing a Discussion Forum in PHP with Recursion
  • Getting started with the forum: defining the structure of the MySQL database table
  • Processing forums threads: defining the "ThreadProcessor" class
  • Displaying the forum: looking at the "fetchTitles()," fetchMessages()" and "createThreadForm()" methods
  • The discussion forum in action: putting the "ThreadProcessor" class to work

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Developing a Discussion Forum in PHP with Recursion - Getting started with the forum: defining the structure of the MySQL database table
    ( Page 2 of 5 )

    To start building this simple discussion forum, what I'll do first is define the structure of the MySQL database table that will serve for storing user data, such as messages, user names, email addresses, and so on. At the same time it will be used to construct a logical tree, in such a way that it can be traversed by a recursive function (or method, to be more accurate), in order to display all this data.

    Keeping in mind the database structure that I just explained above, here is the SQL code for creating the "forum" database table:

    CREATE TABLE forum
    (
    id INT(4) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    parent_id INT(4) UNSIGNED NOT NULL,
    name CHAR(50) NOT NULL,
    email CHAR(50) NOT NULL,
    title CHAR(50) NOT NULL,
    message TEXT NOT NULL
    );

    As you can see, the above sample "forum" database table is comprised of six fields: id, parent_id, name, email, title and message respectively, which are quite descriptive about the type of data they will house. However, let me stop for a while on the "parent_id" field, since it's important to know the meaning of it. Essentially, the values this field will store will be the ID of the corresponding parent node within the structure of a linked tree, so if a particular forum thread has no associated parent (placed on top of the tree), then obviously this value will be 0. In a similar fashion, the different branching threads will be generated by assigning the corresponding parent IDs to each row, as the tree structure goes deeper and deeper.

    To illustrate how the above linked tree works, here is a schematic example of the "forum" database table, populated with a few records:

    In the above example, the database table contains six forum threads, where the two first are main threads, that is their parent_id fields are equal to 0, then the two subsequent ones are sub threads of threads 1 and 2 (parent_id=2 and parent_id=1), and finally the last threads are also sub threads of threads 3 and 4 respectively. Quite understandable, right?

    As you can see, a linked tree structure is pretty easy to be constructed by using a simple database table, and based on this tree structure, the discussion forum will work properly.

    Now that you know how the "forum" database looks, it's time to leap forward and begin coding the PHP class responsible for making the forum work as expected. To see how this will be achieved please read the next few lines.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT