nested set, how to set left and right value with php&mysql
when i search on the internet about nest开发者_如何学Pythoned set, everyone assume i have already left and right values. but i dont have (; i have id, name, parent_id as column. how can i find left and right values?
i guess, i must use recursive alg. but not design it yet.
thanks a lot, erman
Your current model is called an adjacency list. In order to get left and right values, you'll need to perform a push down stack algorithm to convert your model to a nested set.
Here's an example: http://data.bangtech.com/sql/nested_set_treeview.htm
You can also search the web for other conversions from adjacency list to nested set.
Hope that helps!
精彩评论