the singularity of being and nothingness
Archive for March, 2012
PHP Diversion: Making Nested Arrays from Query Data
Mar 1st
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.
Sure, I can do a fair amount of things in PHP…you know, querying databases, echoing content, that kind of stuff. Where I really get hurt, though, is when things start to get complex.
Some ContextNOTE: 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.
For example, I recently needed to build out an ExtJS View, and I wanted to have some pretty heavily-nested data. My ideal outcome would print something to the page like so:
Main Group 1 Category 1 Name 1 Name 2 Fav Color 1 Fav Color 2 Main Group 2 Category 1 Name 1 Name 2 Main Group 3 Category 2 Name 1 Category 3 Name 1
And so on. In other words, each step in the “tree” can have multiple children, which can themselves have multiple children, ad infinitum.
Now in ExtJS, creating a View is dead simple. You simply have to pass the View a JSON structure wherein each level is More >