co.ador Posted April 24, 2011 Share Posted April 24, 2011 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 />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234571-foreach-loop-returning-extra-data/ Share on other sites More sharing options...
spiderwell Posted April 24, 2011 Share Posted April 24, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/234571-foreach-loop-returning-extra-data/#findComment-1205485 Share on other sites More sharing options...
ShoeLace1291 Posted April 24, 2011 Share Posted April 24, 2011 You might want to check out using left joins in your SQL... I haven't used them in a while but it might be what you're looking for. Quote Link to comment https://forums.phpfreaks.com/topic/234571-foreach-loop-returning-extra-data/#findComment-1205487 Share on other sites More sharing options...
co.ador Posted April 24, 2011 Author Share Posted April 24, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234571-foreach-loop-returning-extra-data/#findComment-1205594 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.