Re: Array output from function into a new query



Stefan Rybacki schreef:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marc schrieb:

Hi there,



Hi


I've got this function and I want to fill a new query with the output of
this function. But I only get one value out of the array. How can I pass
the output of this function into a new query?

tnx marc



ok lets have a look of what you're trying to achieve.


// $parent is the parent of the children we want to see
// $level is increased when we go deeper into the tree,
// used to display a nice indented tree
function display_children($parent, $level) {
// retrieve all children of $parent
$result_btnt = mysql_query('SELECT nt FROM btnt '.
'WHERE bt="'.$parent.'";');

// display each child
while ($row = mysql_fetch_array($result_btnt)) {
// indent and display the title of this child

return $row['nt'];


return *exits* the current function



// call this function again to display this
// child's children
display_children($row['nt'], $level+1);



I guess what you want is to move return $row['nt'] over here and you
might don't want to miss to add a check for the current level before you
call display_children (just in case you don't want to display the entire
tree).


Btw. your database design is not the best for what you're doing, because
you're querying your database very often to retrieve the tree until a
specific level.
You can do better doing for example one of the following steps:
- - for example if you know your max tree depth, create just one query
with as much as joins as levels, and retrieve the tree at once (could be
slow on big level depths)
- - use a different database design like nestes sets

Regards
Stefan


}

}


Hi Stefan,

I don't know what the max tree depth is, because for every bt/nt query it is different.

Do you know how I can 'export' the full array out of this function to a query?
Because when I move the $row['nt'] to the point you suggested. I only get one result instead of the whole array..

Regards
Marc
.



Relevant Pages

  • Re: method for making categories/subcategories.
    ... tree storage, you either shift the processing time to tree ... Resulting in a minimum of one query per ... Do it in PHP with ONE function (as I said before, ... Now Stick it in an array. ...
    (comp.lang.php)
  • Re: method for making categories/subcategories.
    ... tree storage, you either shift the processing time to tree ... Resulting in a minimum of one query per ... Do it in PHP with ONE function (as I said before, ... Now Stick it in an array. ...
    (comp.lang.php)
  • Re: Easy balanced tree
    ... The tree can hold between 4 and 7 values, if it was lower than 4 ... then the array would be smaller so we ignore those cases. ... Secondly there is wasted space in the middle of the array (with ... rdrop nip nip; ...
    (comp.lang.forth)
  • Re: Is it possible to have mutable-in-place (associative-)array objects in PHP?
    ... This is the way all languages work. ... just that array variables aren't objects ... and for each I must find the appropriate path in the tree I'm ... treeptr <- rootOfTree ...
    (comp.lang.php)
  • Re: [opensuse] Recover md RAID-1.
    ... md: md0 stopped. ... Then try booting the array with just /dev/sdb1 as a member. ... A ball hitting a tree shall be deemed not to have hit the tree. ...
    (SuSE)