Welcome Guest, Not a member yet? Register   Sign In
Hierarchical <ul><li> from MySql
#2

[eluser]Grahack[/eluser]
Hi! I love these problems, so I take some time to discuss a bit but not enough to give you much code.
First, there are different ways to store hierarchical info in a db. Look at this post pointing to interesting articles. You'll find other useful posts searching for "nested set" in this forum.

So you "choosed" to associate a parent to each item. This needs to be processed RECURSIVELY. That's why it's intensive for big sets of information, it can't be done with a single query. Each node searches for his children with one more query. If you don't have more than 10 levels and 50 items, I bet it will be ok. More precisely, here you even want to have the full tree, so what I would do is make one big query to retrieve every item, then process them to build the tree with php.

You'll have to create a query that will build the $children array, each $child will have an url key, a name key and a parent_id key. That's easy.

1st method (use your code and be able to reuse the tree):
1st step:
Now I don't know how (in your project you had with your friend) precisely you build the $child['children'] array, but it's not very tricky: for each item, loop through the items and stick each children to him (could be optimized).
2nd step:
Recurse with the code your friend gave you.

2nd method: do the two steps above in the same recursive process


Messages In This Thread
Hierarchical <ul><li> from MySql - by El Forum - 12-15-2007, 04:51 PM
Hierarchical <ul><li> from MySql - by El Forum - 12-16-2007, 02:25 AM
Hierarchical <ul><li> from MySql - by El Forum - 12-16-2007, 09:22 PM
Hierarchical <ul><li> from MySql - by El Forum - 12-16-2007, 09:40 PM
Hierarchical <ul><li> from MySql - by El Forum - 12-17-2007, 04:20 PM
Hierarchical <ul><li> from MySql - by El Forum - 12-18-2007, 06:00 AM
Hierarchical <ul><li> from MySql - by El Forum - 12-18-2007, 08:53 AM
Hierarchical <ul><li> from MySql - by El Forum - 12-18-2007, 09:04 AM
Hierarchical <ul><li> from MySql - by El Forum - 12-20-2007, 02:01 AM
Hierarchical <ul><li> from MySql - by El Forum - 10-25-2009, 01:49 PM
Hierarchical <ul><li> from MySql - by El Forum - 10-26-2009, 04:14 AM
Hierarchical <ul><li> from MySql - by El Forum - 08-04-2010, 09:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB