PHP
  Home arrow PHP arrow Page 3 - Creating a Simple Threaded Discussion Forum
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? 
Google.com  
PHP

Creating a Simple Threaded Discussion Forum
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 29
    2006-10-16


    Table of Contents:
  • Creating a Simple Threaded Discussion Forum
  • Index.php
  • viewarticle.php
  • Postre.php

  • 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


    Creating a Simple Threaded Discussion Forum - viewarticle.php
    ( Page 3 of 4 )

    The screen shot above shows the viewarticles page listing the replies to a thread.  The function below is responsible for doing exactly that:

    //view replies to selected threads -viewarticles.php
    function
    viewthread(){
          include("config.php");
            $query="select * from test where uid =$parent";
          if ($r =mysql_query($query)) {
     //Retrieve records
     while ($row =mysql_fetch_array($r)) {
    //transfer values
     $child=$row['child'];
    //$parent=$row['parent'];
    $uid=$row['uid'];
    $name=$row['name'];
    $title=$row['title'];
    $message=$row['message'];
    $date=$row['date'];
    //put values in session vars
    $_SESSION['title']=$title;
    $_SESSION['message']=$message;
    $_SESSION['parent']=$parent;
    $child=$_SESSION['parent'];
    $child=$child + 1;
    $_SESSION['child']=$child;
    //display values
         echo "<b>Title:</b> $title<br> <b>By:</b> $name <br> <b>Date
    Posted:</b> $date<br />";
             echo "<b>Message:</b> $message <br />";
             }
             }
             }

    It's relatively straightforward. This function receives a $parent number from the index.php page and uses that number to retrieve all records with a uid equal to the  $parent value, as in:  $query="select * from test where uid =$parent";

    Also, on the same page the code below is used to get all the replies related to the current thread:

    $parent =$_GET['parent'];
    include("config.php");
     $query="select uid,name,title,message,parent,date from test
    where parent=$parent order by date,parent desc ";
     if ($r =mysql_query($query)) {
     //$num = mysql_num_rows($r);
     //Retrieve records
     while ($row =mysql_fetch_array($r)) {
    $name=$row['name'];
    $uid=$row['uid'];
    $title=$row['title'];
    $message=$row['message'];
    $date=$row['date'];
    //add bullet points
    echo  '<ul type="disc">';
    echo "<li>";
    //echo "<a href="index.php?parent=$uid"> $title </a>";
    echo "<a href="viewarticle.php?parent=$uid"> $title </a> ";
    echo "-- by <b>$name</b> $date<br/>";
    echo "</li></ul>";
    }
    }

    This code receives the $parent value from the index page and uses that value to retrieve all records whose parent value matches the value in the $parent variable. I hope this is not too confusing. Say a new thread is created, and given a uid of 7. All the replies to this thread will have 7 in the parent column of the database. Therefore, if you want to find all the replies to this thread, all you have to do is to retrieve all the records that have seven in their parent column. And this is what happens here.



     
     
    >>> More PHP Articles          >>> More By Jacques Noah
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek