Jump to content

how do i find out if a parent has any children


ricky spires

Recommended Posts

how do i find out if a parent has any children?

 

for example

 

id - name - parent_id

 

1  -  title1  -  0  (parent)

2  -  title2  -  0  (parent)

3  -  link1  -  1  (child)

4  -  link2  -  1  (child)

5  -  link3  -  2  (child)

5  -  link4  -  2  (child)

 

the above has 2 parent with 2 links each.

 

so..

if an id has no "parent_id" pointing to it must be a child

if an id has "parent_id" pointing to it must be a parent

 

 

i have a list

 



<ul>

<li><a href="">'.$link.'</a></li>

<li><a href="" class="subTitle">'.$title.'</a>

     <ul class="subLink">
     <li><a href="">'.$link.'</a></li>
     </ul>
</li>

</ul>

 

 

so i want to do something like

 

if id has no "parent_id" pointing to it, it is a $link

if id has "parent_id" pointing to it, it is a $title

 

 

 

 

any thoughts

 

thanks

ok.

 

but say i have nested levels

 

in the part that says ***THIS IS WHERE IS WANT THE CODE***    i want it to do some thing like .... if there are children pointing to an id make it a title of a nested level (class="subTitle)  else its just a link in the list

 

<div>
$header = Text::find_by_parentID(0);  		
foreach ($header as $headers){
$Hid = $headers->id;
        $Hname = $headers->name;
        $Hparent = $headers->parent;	

echo $Hparent == 0 ? '<h3 class="header">'.$Hname.'</h3>' : '';

echo'
<ul class="nav">';

	//FIND NESTED TITLES / LINKS
	$headText = Text::find_by_child($Hid);  		
        foreach ($headText as $headTexts){
        $Cid = $headTexts->id;
                $Cname = $headTexts->name;
                $Cparent = $headTexts->parent;

	echo ***THIS IS WHERE IS WANT THE CODE***  ? '<li><a href="">'.Cname.'</a></li>' : '<li><a href="" class="subTitle">'.Cname.'</a>';	

	echo'
	<ul class="subLevel" style="margin-left: 15px">';
		   
	//FIND SUBLINK
	$sub = Text::find_by_child($Cid);  		
        foreach ($subs $subs){
                $name = $subs->name;
     	        echo'<li><a href="">'.$name.'</a></li>';
        }
	echo'	
	</ul>
	</li>';	
	}
echo'</ul>';
}
echo'</div>';
?>

can anyone help with this please. ?

 

:confused:

 

all i what to do is find some code that says...

 

if ID has ant CHILDREN do 1thing if not do another thing..

 

for example:

 

$id - $name - $parent_id

 

1  -  title1  -  0  (parent)

2  -  title2  -  0  (parent)

3  -  link1  -  1  (child)

4  -  link2  -  1  (child)

5  -  link3  -  2  (child)

5  -  link4  -  2  (child)

 

if $id HAS ANY $parent_id with the same number 
echo  <li class="PARENT">'.$name'.</li>
else
echo  <li class="CHILD">'.$name'.</li>

 

 

 

any ideas.....

 

 

 

 

this is the actual code ..

the part that says "****THIS IS WHERE IM STUCK***" is where i need to put some code that says "if $id HAS ANY $parent_id with the same number make the li a title."

 

 

<?PHP require_once("includes/initialize.php"); ?>
<?PHP

echo'
<div class="arrowlistmenu">';


$nav = PhLists::navOrder($PHLlno, $PHLorb, $PHLord);

//FIND HEADER
$navHead = PhLists::find_by_parentID(0);
foreach($navHead as $navHeads){
    $headID = $navHeads->id;
$headLnk = $navHeads->pageLink_id;	

$PCBhead = PCbridge::find_NavText($headLnk, $langID);
foreach ($PCBhead as $PCBheads){
$headText = $PCBheads->pageContent_id;

$headText = PageContent::find_text($headText);  		
foreach ($headText as $headTexts){
$header = $headTexts->title;	

echo $navPnt == 0 ? '<h3 class="menuheader expandable">'.$header.'</h3>' : '';

echo'
<ul class="categoryitems">';

	//FIND LINK & TITLES
	$navLink = PhLists::find_by_child($headID);
	foreach($navLink as $navLinks){
	$nLid = $navLinks->id;	
	$nLink = $navLinks->pageLink_id;
	$nLinkPnt = $navLinks->parent_id;
	$nLinklvl = $navLinks->level;

	$PCBlink = PCbridge::find_NavText($nLink, $langID);
	foreach ($PCBlink as $PCBlinks){
	$linkText = $PCBlinks->pageContent_id;

	$lnkText = PageContent::find_text($linkText);  		
	foreach ($lnkText as $lnkTexts){

	echo ****THIS IS WHERE IM STUCK****  ? '<li><a href="">THIS IS A LINK='.$lnkTexts->title.'</a></li>' : '<li><a href="" class="subexpandable">THIS IS A TITLE='.$lnkTexts->title.'</a>';	


			echo'
			<ul class="subcategoryitems" style="margin-left: 15px">';
		    
			//FIND SUBNAV SUBLINK
			$subNav = PhLists::find_by_child($nLid);
			foreach($subNav as $subNavs){
			$sLinkID = $subNavs->pageLink_id;
			$sLinkPnt = $subNavs->parent_id;
			$sLinklvl = $navLinks->level;

			$PCBsubLink = PCbridge::find_NavText($sLinkID, $langID);
			foreach ($PCBsubLink as $PCBsubLinks){
			$subLinkText = $PCBsubLinks->pageContent_id;

			$subLnkText = PageContent::find_text($subLinkText);  		
			foreach ($subLnkText as $subLnkTexts){
			$subLink = $subLnkTexts->title;	

				echo'
				<li><a href="">THIS IS A SUBLINK='.$subLink.'</a></li>';
			}}}
			echo'	
			</ul>
		</li>';	
	}}}
echo'</ul>';
}}}
echo'</div>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.