Jump to content

how do i loop through a nested list ?


ricky spires

Recommended Posts

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

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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 ?

 

 

Link to comment
Share on other sites

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>';
			}

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.