views:

122

answers:

1

Hey guys,

I am trying to make the following loop work. Basically, I am trying to display the children as options. Why doesn't it work? The optiongroups are being displayed. And the arrays are constructed the right way.

{foreach from=$tpl_parents item='row' key='i'}
    <optgroup label="{$row.NAME}">
        {foreach from=$tpl_children.$i item='child' key='y'}
            <option value="{$y}">{$child.VALUE}</option>
        {/foreach}
    </optgroup>
{/foreach}

The array I am trying to loop through is constructed this way: Parent array:

array(328) {
 [0]=>
   array(42) {
    ["ID"]=>
     string(4) "123"
    ["NAME"]=>
     string(6) "blabla"
    ...
    ...

Child array:

array(192) {
  [123]=>
    array(2) {
      [881]=>
        array(11) {
            ["CHILD_ID"]=> string(5) "881"
            ["PARENT_ID"]=> string(4) "123"
            ["VALUE"]=> string(2) "No"
    ...
    ...
A: 

Looks like you need to nest another foreach in there to get the actual child item array:

{foreach from=$tpl_parents item='row' key='i'}
    <optgroup label="{$row.NAME}">
        {foreach from=$tpl_children.$i item='child' key='j'}
            {foreach from=$child item='child_item' key='y'}
                <option value="{$y}">{$child_item.VALUE}</option>
            {/foreach}
        {/foreach}
    </optgroup>
{/foreach}

It is a bit hard to work out as the arrays you have provided are not complete and do not have their variable names associated with them. eg. $row = array('blah');

Treffynnon