Building a multidimensional JSON array through PHP/MySQL

Bxlcoxvbwlymw

New Member
I am trying to build what I think is a multidimensional array in json through php and a connection to a mysql database.Here's the output I am looking for:\[code\][{"region":"Americas"},{"region":"West","division":"Americas","revenues":"100000","headcount":"6"},{"region":"East","division":"Americas","revenues":"1500000","headcount":"8"},{"region":"South","division":"Americas","revenues":"1000000","headcount":"7"},{"office":"San Francisco","location":"50 Kearny Street", "branch":"West"},{"office":"Los Angeles","location":"200 Sepulveda","branch":"West"},{"office":"New York","location":"Penn Street","branch":"East"},{"office":"Philadelphia","location":"155 Trent","branch":"East"},{"office":"New Jersey","location":"420 Broadway","branch":"East"},{"office":"Atlanta","location":"39000 Parker","branch":"South"}]\[/code\]This gives me the feed into a graphing program that creates the proper visualization. My database returns all the values in the JSON above (region, division, revenues, etc.) EXCEPT for "branch" which I had to hand code myself. I can't sure "region" again (because of the graphing algorithm) so I had to rename it to "branch." Under this current configuration, the "Americas" is the top node, with the "regions" underneath, and then the "branches" under each region as appropriate. So far, I've only been able to build a basic JSON array using PHP and the json_(encode) function ; to get the output above, I edited the file by hand to make sure it would render properly in my graph, which it does.The question I am looking to answer is: what is the fastest and easiest way to build the above array on the fly? Through a loop in PHP, I would imagine, but I can't get my head around what that would look like.I probably left out information you need to help, so this is just to get the ball rolling.Thanks!
 
Top