miob Posted August 29, 2007 Share Posted August 29, 2007 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><? } } Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/ Share on other sites More sharing options...
BlueSkyIS Posted August 29, 2007 Share Posted August 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337312 Share on other sites More sharing options...
miob Posted August 29, 2007 Author Share Posted August 29, 2007 yes that is what i need to do, but still can't get it work cuz there is small problem with parent id, that in each function is different, i need to pass parent id in that function Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337322 Share on other sites More sharing options...
BlueSkyIS Posted August 29, 2007 Share Posted August 29, 2007 I don't see parent id in your original post. Where does it come from? Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337324 Share on other sites More sharing options...
sasa Posted August 29, 2007 Share Posted August 29, 2007 how $forum_replies look like can we see some data and what you want for output Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337326 Share on other sites More sharing options...
miob Posted August 29, 2007 Author Share Posted August 29, 2007 first is $replies[0] then $replies2[0] then $replies3[0]... after function listing() i need to pass that current $replies..[0] to the next function Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337329 Share on other sites More sharing options...
miob Posted August 29, 2007 Author Share Posted August 29, 2007 how $forum_replies look like can we see some data and what you want for output i wanna make a forum, each new quote must get padding-left: 15px, i must see the tree and i can't limit it Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337335 Share on other sites More sharing options...
sasa Posted August 29, 2007 Share Posted August 29, 2007 can we see some data or we most look in cristal sphere Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337347 Share on other sites More sharing options...
miob Posted August 29, 2007 Author Share Posted August 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337352 Share on other sites More sharing options...
miob Posted August 30, 2007 Author Share Posted August 30, 2007 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><? } } Quote Link to comment https://forums.phpfreaks.com/topic/67246-solved-neverending-function/#findComment-337662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.