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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.