Multi Dimensional Array for multi level menu |
[eluser]Unknown[/eluser]
Hello,I'm working on a class that will have a function for getting the results and a function that will format the results from a standard array to a multi dimensional array suitable for looping to create a multi level menu. when i get my results without formatting i get what i expected a single, simple array mixed of level one categories and sub categories. Example Below. original result: Quote:http://bit.ly/VFbVUy Now when i try running the Array through my format function intending to sort the array into categories, sub categories as children. a sample of what i get when using the function is below and a snippet of what i want to achieve but just cant. What i get: Quote:http://bit.ly/VFbmtN What i intended to achieve: Quote:http://bit.ly/VFelTd My model functions are as follows. Code: /* Get Categories Menu My controller function. Code: function index() { This topic is well explained and plenty of examples of my code to help fix the problem i can only help think this will help others in the future better than other posts. Really hope you can help. Been at Google and notepad for days now .... Regards Script Gecko :coolmad:.
[eluser]jmadsen[/eluser]
@Script Gecko reading fast, I'd say look at: Code: $data[$menuItem['cat_id']]['children'][$ID] = &$menuItem; Your $result is an array of arrays, so I think $menuItem is your row array, and causing your problem. However, your menu is only going to work one level deep, which may be enough. Not to sound like a shill for my own stuff, but: http://www.codebyjeff.com/blog/2012/10/n...hy-library Has a function: get_grouped_children($top_id=0) Fetch all descendent records based on the parent id, ordered by their lineage, and groups them as a multi-dimensional array. that might help you out. (or you can just steal the bits you need from there :-) )
[eluser]Unknown[/eluser]
The way of being a good programmer is learning other peoples code and learning new and faster methods. This is allot better for me than you telling me what to do now i can see exactly how it works!! Thanks a lot mate! |
Welcome Guest, Not a member yet? Register Sign In |