st0ked56 Posted March 23, 2013 Share Posted March 23, 2013 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. 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 Quote Link to comment https://forums.phpfreaks.com/topic/276037-nested-foreach-issue/ Share on other sites More sharing options...
haku Posted March 23, 2013 Share Posted March 23, 2013 That's not PHP. Quote Link to comment https://forums.phpfreaks.com/topic/276037-nested-foreach-issue/#findComment-1420456 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.