Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Nested foreach issue

$
0
0

Hello,

I am creating a jquery menu and I am having a problem displaying the correct data. It uses data from MySQL database. When I print the loops not nested the data prints out correctly. You'll see the data above the menu in the picture. 

 

menu.PNG


Once I start nesting the loops, I can't seem to pull the right data, and I am not sure what data it is actually pulling.

This is my html controller:

{foreach from=$aYear item=aYear}
    <p>{$aYear.seasonyear}</p>
{/foreach}
{foreach from=$aTeam item=aTeam}
    <p>{$aTeam.team_id} - {$aTeam.teamname} - 
                        {if $aTeam.season == 0}
                            Fall
                        {elseif $aTeam.season == 1}
                            Winter
                        {elseif $aTeam.season == 2}
                            Spring
                        {elseif $aTeam.season == 3}
                            Summer
                        {/if}</p>
{/foreach}
    <div id="left_block">
        <div class="headerbar">Seasons</div>
        <div id="left_dropbar" class="left_content">


            <!-- First level menu start here -->
            <ul id ="firstlevel">  
                {foreach from=$aYear item=aYear}
                <li><a href="#">{$aYear.seasonyear}</a>
                     <!-- Controls Sub level 1 menu start here -->
                     <ul class="subfirstlevel">
                        {foreach from=$aSeason item=aSeason}
                        <li><a href="#">
                        {if $aSeason.season == 0}
                            Fall
                        {elseif $aSeason.season == 1}
                            Winter
                        {elseif $aSeason.season == 2}
                            Spring
                        {elseif $aSeason.season == 3}
                            Summer
                        {else}
                            Error!
                        {/if}
                        </a>
                            <!-- Controls Sub level 2 menu start here -->
                            <ul>
                                {foreach from=$aTeam item=aTeam}
                                 <li><a href="#" onclick="displaySeason('{$aTeam.team_id}')" id="menu_teamname">{$aTeam.teamname}</a></li>
                                {/foreach}
                            </ul>
                            {/foreach}
                            <!-- Controls Sub level 2 menu end here -->
                        </li>
                     </ul>                    
                </li>
                {/foreach}
             <!-- Controls Sub level 1 menu end here -->
            </ul>
            <!-- First level menu end here -->
            <button id="team-season">Add Team</button>
            <div id="teamadd"></div>
        </div>
    </div>

 

Also it looks like my code is not looping all the way through. Should display to 1st level menus (2013, 2012). Second level should have 1 item (Fall) and third level should have 1 item (Raptors).

Any help would be appreciated. Let me know if you need more information.

 

Thank you,

Mike

 

 


 

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles