Jump to content

Nested foreach issue


st0ked56

Recommended Posts

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. 

 

post-143625-0-25483200-1363998300_thumb.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

 

 


 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.