Skip to main content
Participant
June 23, 2006
Question

PHP: Nested repeat region in nested repeat region

  • June 23, 2006
  • 2 replies
  • 859 views
Does anyone know how to this:

I wanna have nested repeat region in repeated region. Example

Parent Category
Category name
Category name
Category name

Parent Category
Category name
sub category name
sub category name
sub category name

Category name
Category name
sub category name
sub category name
sub category name

Parent Category
Parent Category
Parent Category

Can anyone help me with this?

Thanks in advance.
This topic has been closed for replies.

2 replies

Inspiring
June 23, 2006
Tom Muck has a free extension that will do what you require:
http://www.tom-muck.com/extensions/help/simulatednestedregion/

--
Dave Buchholz
I-CRE8
www.i-cre8.co.uk


"dreamworms" <dreamworms@siteatelier.com> wrote in message
news:e7gacv$fc5$1@forums.macromedia.com...
Does anyone know how to this:

I wanna have nested repeat region in repeated region. Example

Parent Category
Category name
Category name
Category name

Parent Category
Category name
sub category name
sub category name
sub category name

Category name
Category name
sub category name
sub category name
sub category name

Parent Category
Parent Category
Parent Category

Can anyone help me with this?

Thanks in advance.


Inspiring
June 23, 2006
dreamworms wrote:
> I wanna have nested repeat region in repeated region.

I'm not saying it's necessarily the best way to do it, but this is
certainly one way. The categories are stored as a multidimensional,
associative array. Each element needs to be an array, even if it's
empty. The recursive function displayCats() then loops through the whole
thing and produces the nested results you seek.

<?php
$cats = array('Top Level 1' => array(
'sub a' => array(), 'sub b' => array(), 'sub c' => array()),
'Top Level 2' => array(
'sub d' => array(
'sub sub a' => array(), 'sub sub b' => array()),
'sub e' => array(
'sub sub c' => array(), 'sub sub d' => array()),
'sub f' => array(
'sub sub e' => array(), 'sub sub f' => array(), 'sub sub g' =>
array())),
'Top Level 3' => array(),
'Top Level 4' => array(),
'Top Level 5' => array());

function displayCats($array) {
echo "<ul>\n";
foreach ($array as $key => $value) {
echo "<li>$key</li>\n";
if ($value) {
displayCats($value);
}
}
echo "</ul>\n";
}

displayCats($cats);
?>

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/