ricky spires Posted January 16, 2012 Share Posted January 16, 2012 hello. i have a list that is pulling info from a db but the sub levels are not showing correctly. basically there are titles that could be in any order then under each title there are lists that could be in any order then some of the lists might also have nested lists which could be in any oder. its not the full html yet but I'm stuck because it echoes out the titles fine but the links are not being listed under each title. all the links are being listed under the first title only. $PCa = PageContent::find_by_pageContID($PCidA); foreach ($PCa as $PCas) { $title = $PCas->title; $link = $PCas->link; echo' <div class="arrowlistmenu">'; if (!empty($title)) { echo' <h3 class="menuheader expandable">'."{$title}".'</h3>'; } if (!empty($link)) { echo' <ul class="categoryitems"> <li><a href="#">'."{$link}".'</a></li> </ul>'; } echo'</div>'; } this is an example of the html. <div class="NAV"> <h3>CAT TITLE</h3> <ul class="CAT ITEM"> <li><a href="#">LINK</a></li> </ul> <h3>CATT TITLE</h3> <ul class="CAT ITEM"> <li><a href="#">LINK</a></li> <li><a href="#" class="SUB CAT">NESTED LEVEL TITLE</a> <ul class="SUB CAT ITEM" style="margin-left: 15px"> <li><a href="#">LINK</a></li> </ul> </li> <li><a href="#">LINK</a></li> </ul> </div> thanks Quote Link to comment https://forums.phpfreaks.com/topic/255179-how-do-i-loop-through-a-nested-list/ Share on other sites More sharing options...
Morpheous Posted January 16, 2012 Share Posted January 16, 2012 Do you have more than 1 link per title? If this is the case, you may be missing a nested loop. Quote Link to comment https://forums.phpfreaks.com/topic/255179-how-do-i-loop-through-a-nested-list/#findComment-1308362 Share on other sites More sharing options...
ricky spires Posted January 16, 2012 Author Share Posted January 16, 2012 i made a little progress. <div class="arrowlistmenu">'; $PCa = PageContent::find_by_pageContID($PCidA); foreach ($PCa as $PCas) { $title = $PCas->title; $link = $PCas->link; if (!empty($PCidA) && !empty($title)) { echo'<h3 class="menuheader expandable">'."{$PCidA}{$title}".'</h3>'; echo' <ul class="categoryitems"> <li><a href="#">'."{$PCidA}{$link}".'</a></li> </ul>'; } echo'</div>'; this echos 5 titles with the ids of each title under as a list. like this <ul>id-title</ul> <li>id</li> <ul>id-title</ul> <li>id</li> <ul>id-title</ul> <li>id</li> <ul>id-title</ul> <li>id</li> <ul>id-title</ul> <li>id</li> it doesn't echo out the links Quote Link to comment https://forums.phpfreaks.com/topic/255179-how-do-i-loop-through-a-nested-list/#findComment-1308372 Share on other sites More sharing options...
ricky spires Posted January 16, 2012 Author Share Posted January 16, 2012 at the moment i have 2 links in each title each link has a parent id of the title its under thanks Quote Link to comment https://forums.phpfreaks.com/topic/255179-how-do-i-loop-through-a-nested-list/#findComment-1308379 Share on other sites More sharing options...
ricky spires Posted January 17, 2012 Author Share Posted January 17, 2012 im still stuck . if anyone could help it would be fantastic. thanks this the code now function listNavText($PHGlidA, $PHLobA, $PHLodA){ $langBS = basicSettings::find_by_id(1); $langID = $langBS->language_id; $PHLoa = PhLists::find_by_order($PHGlidA, $PHLobA, $PHLodA); foreach ($PHLoa as $PHLoas){ $PHLidA = $PHLoas->id; $style = $PHLoas->style_id; $level = $PHLoas->levels; $parent = $PHLoas->parent_id; $destination = $PHLoas->destination_id; $PCba = PCbridge::find_by_list($PHLidA, $langID); foreach ($PCba as $PCbas){ $PCidA = $PCbas->pageContent_id; $PCa = PageContent::find_by_pageContID($PCidA); foreach ($PCa as $PCas) { $title = $PCas->title; $link = $PCas->link; echo' <div class="arrowlistmenu">'; if (!empty($title)) { echo'<h3 class="menuheader expandable">'.$title.'</h3>'; } echo' <ul class="categoryitems">'; if ($PHlvlA == "1"){ echo'<li><a href="#">'.$link.'</a></li>'; if ($PHlvlA == "2"){ echo' <li><a href="#" class="subexpandable">'.$title.'</a> <ul class="subcategoryitems" style="margin-left: 15px"> <li><a href="#">'.$link.'</a></li> </ul> </li>'; } } echo'</div>'; } } } } how do i loop through this ???? maybe a while loop ? Quote Link to comment https://forums.phpfreaks.com/topic/255179-how-do-i-loop-through-a-nested-list/#findComment-1308703 Share on other sites More sharing options...
ricky spires Posted January 17, 2012 Author Share Posted January 17, 2012 this works in html not pulling from the db echo' <div class="arrowlistmenu">'; if (!empty($title)) { echo'<h3 class="menuheader expandable">'.$title.'</h3>'; echo' <ul class="categoryitems">'; //if ($PHlvlA == "1"){ echo'<li><a href="#">link L1</a></li>'; //} //if ($PHlvlA == "2"){ echo' <li><a href="#" class="subexpandable">sub title</a> <ul class="subcategoryitems" style="margin-left: 15px"> <li><a href="#">link L2</a></li> </ul> </li>'; //} } echo'</div>'; } Quote Link to comment https://forums.phpfreaks.com/topic/255179-how-do-i-loop-through-a-nested-list/#findComment-1308708 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.