Ok so I copped a simple recursive function from a tutorial here at Sitepoint (I searched on "Recursive" on the front page). Now, it works fine for showing my trees of comments and their replies in a threaded-like fashion. Here's the rub: I am trying to display a message (parent=0) and then use the function to show all of its replies... so I got the function to skip showing the top node just by telling it to bypass output if parent=0. But here's how I want it to work:

Say a Thread has 10 replies. 5 are all on on the first level of replies and each reply has one reply for a total of 10. Now, the way I want it to work is if you click on, say, Reply 1, it wil display the full text of Reply 1 with a link to Reply1a underneath it. That's the easy part. The hard part is, I want it to then go on to display the full text of Reply 2 underneath Reply 1, complete with a link to Reply 2a, and so on such that every reply on the same level of a certain reply, and below it in timestamp, is displayed as full text with its own replies in link form. This is similar to how a site like Slashdot works in threaded mode and I'm sure countless others.

So what I've got happening is a query that outputs the full text of the called reply, followed the recursive function which checks for children of that reply and creates links to them if they exist. Then I put this entire piece of code inside another while loop such that it repeats for every reply that has the same parent ID as the one being displayed at the top. But the problem is, when it loops through the second time and thus the recursive function has to run to check to see if the second same-level reply has any children, I get a "Fatal error: Cannot redeclare display_children2() in /home/httpd/html/phpbbs/showThread.php on line 278" error.

Here's the code if it'll help...


PHP Code:

//This first query basically looks for same-level replies and adds them // to a result set if there are any

                
$threadSameLevel 'SELECT *'
                           
.' FROM msgcomments INNER JOIN users using (uid) WHERE parent="'.$row_threadFirst['parent'].'"'
                        
.' AND cid != "'.$row_threadFirst['cid'].'"';
                
                
$result_threadSameLevel mysql_query($threadSameLevel$Zeus);
                
$row_threadSameLevel mysql_fetch_array($result_threadSameLevel) ;
                
if (
$row_threadSameLevel != "") {

    do {        

[
Blah put full text of reply here]
    
                            
        function 
display_children2($parent2) {
       
// retrieve all children of $parent2
       
$thread2 mysql_query('SELECT *'
                            
.' FROM msgcomments INNER JOIN users using (uid)'
                            
.' WHERE parent="'.$parent2.'" AND tid="'.$_GET['tid'].'";');
    
       
// display each child
       
while ($row_thread2 mysql_fetch_array($thread2)) {
           
// indent and display the title of this child 
           
           
if ($row_thread2['parent'] != "0") : 
           &
nbsp;
            echo [
Blah put links to children replies here]
            
              endif;
        
        
$child_cid $row_thread2['cid'];
        
       echo 
"   ";
       
display_children2($child_cid);
      
           }
        } 
//Close function
            
            
$cid $row_threadSameLevel['cid'];
            
display_children2($cid);

    } while (
$row_threadSameLevel mysql_fetch_array($result_threadSameLevel)); } //Endif there are same level replies