

With this in mind, my second approach took the form of trying to iteratively reduce the data being dealt with at any particular “level” of the process. The flags became a mess really quickly, because they were each trying to keep track of their place within the whole data set, instead of a “parent” only being concerned about whatever children it might have. One big problem, in my estimation, is that I was getting tripped up by the conversion from the flat result set from MySQL to the nested-array model I needed.

So I stepped back a bit, and tried to think a bit more critically about my approach. it was a headache to write, and the thought of having to do it N times for each query was maddening. Not only is it unsustainable as you have to replicate the functionality for EVERY change in data, but it’s also a nightmare because there are only so many “flags” and “nested flags” that the human brain can keep track of at a single time. However, when you have to start nesting data in more complex fashions, it becomes incredibly unwieldy. Sure, it’s not a huge deal when you have a simple “group” -> “item” relationship. While this approach certainly works (I used it in my first several *attempts*), it gets hairy really quickly. When you reach a new “group” (e.g., group value != flag), reset the group flag, create a new array for the group data, nest child data, etc. The PHP concatenation operator is one of the important operators in PHP, which is used to combine two string values to create one string, and for concatenation assignment. Set a “flag” for the group (this will be updated when you move to a different group).For the most part, the answers I found suggested doing something like this: So not knowing what to do, I headed out to The Google, and asked it to tell me about “creating nested json” and “nested data” and the like. Unfortunately, there is nothing in PHP like ColdFusion’s amazing “group” attribute in the tag. Rather, it was turning a MySQL query result set into a structure that could be serialized into the proper format and sent off to ExtJS. My problem, however, was not with the ExtJS side. You simply have to pass the View a JSON structure wherein each level is an array of objects. Now in ExtJS, creating a View is dead simple. In other words, each step in the “tree” can have multiple children, which can themselves have multiple children, ad infinitum. My ideal outcome would print something to the page like so: Main Group 1Īnd so on. Some Contextįor example, I recently needed to build out an ExtJS View, and I wanted to have some pretty heavily-nested data. NOTE: If you don’t particularly feel like reading and just want to see some code, be sure to check out my GitHub repo for this. Where I really get hurt, though, is when things start to get complex. Sure, I can do a fair amount of things in PHP…you know, querying databases, echoing content, that kind of stuff. As if the title doesn’t give away the whole plot, I’m currently working on a project that uses PHP–gasp! No, I’ve not abandoned ColdFusion, and too be completely honest, I’m kind of a PHP noob.
