Jump to content

[SOLVED] neverending function


miob

Recommended Posts

hi !

 

i have a big problem i have no clue how to code it. need to make a tree in function

 

i think i need to use same function in function, is that possible ?

 

 

example:

 

i have this working but only in 4 layers, i need to have it unlimited...

i can add next and next same thing over and over but i don't think it's good solution:

 

 

 

foreach ($forum_replies as $key => $replies){

if (!$replies[4])

{

listing($replies,'false');

 

foreach ($forum_replies as $key => $replies2){

  if ($replies2[4]==$replies[0]) {

  listing($replies2,'true');

foreach ($forum_replies as $key => $replies3){

  if ($replies3[4]==$replies2[0]) {

  listing($replies3,'true');

foreach ($forum_replies as $key => $replies4){

  if ($replies4[4]==$replies3[0]) {listing($replies4,'true'); ?></div><?}

}

  ?></div><?

  }

}

  ?></div><?

  }

}

?></div><?

}

}

 

Link to comment
Share on other sites

it looks like you want to use a recursive function that calls itself.

function recurseFunc($all_forum_replies) {
    foreach ($all_forum_replies as $key => $replies) {
        if (!$replies[4] || $replies[4] == $replies[0]) {
           listing($replies,'false');

           recurseFunc($replies);
        }
    }
}

 

call it once:

 

recurseFunc($forum_replies);

 

.... or similar

Link to comment
Share on other sites

i don't wanna put URL's here...

 

forum_replies is array with posts in the forum

function listing will show up post from user.

 

something like this :

 

 

<div class="riadok1" style="height:50px; width:100%; repeat-x top; ">

<div class="autor" style="float:left; margin:3px; ">title: <b>Re: title of post</b><br>Author: miob, 28.08.07 - 02:46</div>

<div class="prisp" style="float:right; margin:3px;"><a href='?thread=5&reply=4#p4' name='p4'>Quote this post</a> </div>

</div>

<div style="clear: both;"></div>

<p style ="margin:3px;">text of the post</p>

 

 

and if there is no quote in the this post, i show "</div>"

 

i hope it's clear now

 

Link to comment
Share on other sites

i managed to code it by myself, took me more hours but i'm glad i did it.

Anyway thank you guys i appreciate your help.

 

here is it if someone could need it ever:

 

function recurseFunc($all_forum_replies,$parent) {

    foreach ($all_forum_replies as $key => $replies) {

        if (($replies[4])&&($replies[4] == $parent)) {

          listing($replies,'true');

          recurseFunc($all_forum_replies,$replies[0]);

            ?></div><?

        }

    }

}

 

foreach ($forum_replies as $key =>  $replies){

if (!$replies[4]) { listing($replies,'false'); recurseFunc($forum_replies,$replies[0]);

?></div><?

  }

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.