PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function children($parent) {
global $database;
$result = $db->query("SELECT * FROM tree WHERE (parentId = '".$parent."')");
while ($row = $result->fetch()) {
@extract($row);
echo $treeId;
children($treeId);
// call this function again
// child's children
}
}
i am interested retrieving the $treeId from this function and assign it's value to something else.
if I use
I would suggest adjusting the table schema so it is suited for trees more. Specifically, the various hierarchical structures referred to in various threads.
I'm affraid I don't understand what exactly do you mean, but i'll explain a little what i want to do, maybe this will help.
I have 2 tables.
short example
tree
treeId | parent | Name
1 | | Cuisine
2 | 1 | Chinese
3 | 2 | East China
4 | 2 | West China
and
books
id | tree | BookName | Author
1 | 3 | Some book | Jim
now, I want to delete the record with treeId = 2 from tree table.
Because this is parent for other records in the tree table I need to delete them recursively.
I need that $treeId from my function because I need to check if that $treeId is refference in books table. If it is, then the book that has tree would be deleted.
Hope you understand what I mean.