PHP
  Home arrow PHP arrow Page 3 - Creating a Simple Threaded Discussion ...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Creating a Simple Threaded Discussion Forum
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 24
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


       · Good tutorial, the system did work, although I would suggest cleaning up your code...
       · Well I do hope that everyone finds my article educational. I also thank you for...
       · Really this code i mean Creating a Simple Threaded Discussion Forum is looks prety ...
       · i am not master in php, but i want to become, i had seen ur post, where can i get...
       · I dont understand how it worked although i did what it told me to do it didnt do...
       · hello, i,m asking where to find the code for the files config.php,Tutstyle.css and...
       · Jacques - interesting article and I'd like to try your solution, but where can I get...
       · I am just starting to dig into the world of PHP development. I was so glad when I...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT