i am in a situation where i need to the build the tree from the child nodes i.e i have to travese from child node to the parent my question is is it possible and what is the algorithm for this?
Thanks in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I did something similar to what you’re looking for. I think this should work for you, with minor adjustments. Excuse the WordPressiness – you should be able to figure out what it’s doing, anyways.
This will return an array in reverse order an item or category, and each subsequent parent.
The function to go the opposite direction, from the top category down and will retrieve ALL categories, is:
Between the two of them, you’ll probably be able to cobble something together, I hope :/