Re: Array output from function into a new query



-----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


}

}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (MingW32)

iD8DBQFEKJjhyeCLzp/JKjARAvT0AJwLCsgCA4nBYE7YKiJMKho6ks8zLwCdHoJP
Sr3epvhiYxqYy8wLce8b+1A=
=7evJ
-----END PGP SIGNATURE-----
.



Relevant Pages

  • Re: How to make printer print faster?
    ... > look at the bar graph from the lhs to the center of the display. ... A ball hitting a tree shall be deemed not to have hit the tree. ...
    (freebsd-questions)
  • Re: Suggestions for hierarchical display of data
    ... You could put DataList/Grid on the right side of the tree view without any ... But beside that you could always make a Custom control... ... > Hi Robert, ... >> hierarchical display of data. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: [SWING] Problem with JTree
    ... I use a subclass of JTree that overwrites getCellRendererto get full control over the cell renders. ... If i try to display the structure and content of the object using my tree the tree is not displayed correctly. ... My TreeCellRenderer implementations are subclasses of DefaultTreeCellRenderer and overwrite getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) to determine the current value and call the super method. ... Additionally there's a TreeSelectionListener registered at the JTree that triggers the display of extra information on a separate JPanel. ...
    (comp.lang.java.programmer)
  • Re: Presentation Model GUI Arch and Presenter to View sync
    ...  I think you'd even alter your navigation ... The navigational node in the tree just ... while a Control is a display artifact. ...
    (comp.object)
  • Re: TreeView
    ... the virtual tree since there are still chances that the number of child ... i dont think its a good idea to load the whole data at once in the tree ... data required to display the current tree display. ... added to the treeview) but i dont how to get the tree view somthing like ...
    (microsoft.public.dotnet.framework)