pocobueno1388 Posted June 7, 2007 Share Posted June 7, 2007 Hello =] I am creating a forum script, and I am trying to make it as easy as possible to add/remove forums within the script. The part I am having trouble with is just displaying the different boards in a dynamic way. Here is the format I am using in my array array("Is it a main or sub forum?", "Display Text", "URL", "Display Text") Here is what I currently have it displaying...which is not even close to how I want it. main General Board forum.php?id=1 This should go under the General Boad Sub Genderal forum.php?id=2 This should go under the Sub general Board main Misc Board forum.php?id=3 This should go under the Misc Board Sub Misc forum.php?id=4 This Should go under the Sub Misc Board This is what I am trying to get: General Board <---links to forum.php?id=1 This should go under the General Board Sub General <-----Links to forum.php?id=2 This should go under the Sub General Board Misc Board <---Links to forum.php?id=3 This should go under the Misc Board Sub Misc <---Links to forum.php?id=4 This should go under the Sub Misc board Here is my current code in attempting to get the right output: <?php //Board Information $boards = array( array("main", "General Board", "forum.php?id=1", "This should go under the General Boad"), array("sub", "Sub Genderal", "forum.php?id=2", "This should go under the Sub general Board"), array("main", "Misc Board", "forum.php?id=3", "This should go under the Misc Board"), array("sub", "Sub Misc", "forum.php?id=4", "This Should go under the Sub Misc Board") ); for ($row=0; $row < count($boards); $row++){ for ($col=0; $col < 4; $col++){ //If the category is a sub category, indent it if ($col == 0 && $boards[$row][$col] == 'sub'){ echo ' '; continue; } echo $boards[$row][$col].'<p>'; } } ?> Any help with this is greatly appreciated =D Thanks Quote Link to comment https://forums.phpfreaks.com/topic/54621-solved-formatting-with-loops-and-arrays/ Share on other sites More sharing options...
pocobueno1388 Posted June 7, 2007 Author Share Posted June 7, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/54621-solved-formatting-with-loops-and-arrays/#findComment-270212 Share on other sites More sharing options...
sasa Posted June 7, 2007 Share Posted June 7, 2007 try <?php //Board Information $space = ' '; $ident_array = array('main' => 0, 'sub' => 1, 'subsub' => 2); $boards = array( array("main", "General Board", "forum.php?id=1", "This should go under the General Boad"), array("sub", "Sub Genderal", "forum.php?id=2", "This should go under the Sub general Board"), array("subsub", "Sub Sub Genderal", "forum.php?id=12", "This should go under the Sub sub general Board"), array("main", "Misc Board", "forum.php?id=3", "This should go under the Misc Board"), array("sub", "Sub Misc", "forum.php?id=4", "This Should go under the Sub Misc Board") ); foreach ($boards as $x) { echo str_repeat($space, $ident_array[$x[0]]),'<a href="',$x[2],'">',$x[1],'</a><br />',"\n"; echo str_repeat($space, $ident_array[$x[0]]),$x[3].'<br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54621-solved-formatting-with-loops-and-arrays/#findComment-270263 Share on other sites More sharing options...
pocobueno1388 Posted June 7, 2007 Author Share Posted June 7, 2007 Perfect Sasa =] Thank you so much for taking the time to do that for me =] I just got VERY close to figuring it out, but your code is much more compact and better, so thanks again =D Quote Link to comment https://forums.phpfreaks.com/topic/54621-solved-formatting-with-loops-and-arrays/#findComment-270269 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.