help with foreach loop
<p>Want to get rid of the depth -- 1 field and only display the name and its value.</p>

<p>Functions file</p>

<pre><code>    &lt;?php 
    public function getLocalSubNodes($node_name){
    $stmt = conn::getInstance()-&gt;prepare(" SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth FROM categories AS node, categories AS parent, categories AS sub_parent,
            (
            SELECT node.name, (COUNT(parent.name) - 1) AS depth
            FROM categories AS node,
            categories AS parent
            WHERE node.left_node BETWEEN parent.left_node AND parent.right_node
            AND node.name = :node_name
            GROUP BY node.name
            ORDER BY node.left_node
            )AS sub_tree
    WHERE node.left_node BETWEEN parent.left_node AND parent.right_node
    AND node.left_node BETWEEN sub_parent.left_node AND sub_parent.right_node
    AND sub_parent.name = sub_tree.name
    GROUP BY node.name
    HAVING depth &lt;= 1
    ORDER BY node.left_node");
    $stmt-&gt;bindParam(':node_name', $node_name, PDO::PARAM_STR);
    $stmt-&gt;execute();
    return $stmt-&gt;fetchALL(PDO::FETCH_ASSOC);
    }
    ?&gt;


I instantiate the class calling the getLocalSubNodes functions

    &lt;?php 

    $hierachy = new hierachy;
    $iterator = new RecursiveIteratorIterator(new recursiveArrayIterator($hierachy-&gt;getLocalSubNodes($name1)));
    try {
        foreach($iterator as $key=&gt;$value)
            {
            echo  $key.' -- '.$value.'&lt;br /&gt;';
            }
        }
    catch(Exception $e)
        {
        echo $e-&gt;getMessage();
        } ?&gt;
</code></pre>

<p>resulting in </p>

<blockquote>
  <blockquote>
    <p>name -- mp3 players</p>
    
    <p>depth -- 1</p>
    
    <p>name -- cd players</p>
    
    <p>depth -- 1</p>
    
    <p>name -- 2 way radios</p>
    
    <p>depth -- 1</p>
  </blockquote>
</blockquote>

<p>I only want the </p>

<blockquote>
  <p>name -- mp3 players</p>
  
  <p>name -- cd players</p>
  
  <p>name -- 2 way radios</p>
</blockquote>

<p>want to get rid of the depth.</p>

<p>in the database I don't have such a field called depth it seems to be generated in the query above, I need the query to calculate the depth but I don't want to print the depth and its value, Don't need the depth and its value to be printed or echo. </p>

<p>so I considered it could be the for each loop.</p>

<p>not sure if that's the issue here though. </p>

<p>thanks.</p>
