Jump to content

foreach loop returning extra data.


co.ador

Recommended Posts

I have this query which query the parent.name and the node.name as well.

 

    "SELECT parent.name
    FROM categories AS node,
    categories AS parent
    WHERE node.left_node BETWEEN parent.left_node AND parent.right_node
    AND node.name = '{$node_name}'
    ORDER BY parent.right_node AND node.left_node"

below in the foreach loop is displaying both the node and parent, I only need the parent. I have done a little if statement saying that if node.name not to display but didn't work because both parent.name and node.name are displaying the he same field name.

 

   

 <?php
foreach($iterator as $key=>$value)
        {
     if($value <> "node.name")
        
	echo  $value.'<br />';

        } ?>

Link to comment
Share on other sites

but didn't work because both parent.name and node.name are displaying the he same field name.

 

 

I would say you have answered this yourself, you need to seperate out these 2.

Look again what you are passing into the $iterator array, and make sure you only pass the parent to it?

 

without seeing that part of the code, I cannot be sure what is in that array.

 

Also in your SQL you are asking it to return parentname as  node,  and categories as parent, which only adds to confusing me more! and maybe you?

Link to comment
Share on other sites

I have come to take the Recursive iterator out and did a print_r to see if there was any value and indeed there is value but echoing that value is the problem, is coming out as an array but i can't get to echo the array.

<?php

$hierachy = new hierachy;

    $iterator = $hierachy->singlePathroot($name1);

    try {

          print_r($iterator);

        foreach($iterator as $key=>$value)

            {

    echo $value;

    echo $value['0'];

           

   

   

            }

        }

?>

 

The blockqoute above is the result of an print_r($iterator]

>    Array ( [0] => Array ( [name] => Fruit ) [1] => Array ( [name]

> => Red ) ) ArrayArray

 

and below that print_r we have the test echoes of

 

 

 <?php  echo $value;
        echo $value['0']; ?>

 

which both echoes return as ArrayArray how can I echo those values in the print_r($iterator);  help

 

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.