Sunday, May 9, 2010

Turn database result into array

Programmer Question


Hi everyone,



I have just made the update/add/delete part for the "Closure table" way of organizing query hierarchical data that are shown on page 70 in this slideshare: http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back



My database looks like this:



Table Categories:



ID         Name
1 Top value
2 Sub value1


Table CategoryTree:



child     parent     level
1 1 0
2 2 0
2 1 1


However, I have a bit of an issue getting the full tree back as an multidimensional array from a single query.



Here's what I would like to get back:



 array (

'topvalue' = array (
'Subvalue',
'Subvalue2',
'Subvalue3)
);

);


Update:
Found this link, but I still have a hard time to convert it into an array:
http://karwin.blogspot.com/2010/03/rendering-trees-with-closure-tables.html



Update2 :
I was able to add depths to each of the categories now, if that can be of any help.





Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails