Re: Thinking out loud - a continuation...
| From: | Robert Cummings | Date: | Sat, 24 Mar 2012 18:08:53 +0000 |
| Subject: | Re: Thinking out loud - a continuation... | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-317252@lists.php.net to get a copy of this message | ||
On 12-03-24 01:09 PM, Jay Blanchard wrote:
[snip]The crux of it is:A little tweak here... a little tweak there: <?phpIt works as I expect so far. All I have to do is figure out how to make the element a name: element in the JSON. for instance an element would look like this {$focus =&$focus[$name];[/snip]name: "Bob", children: []} So the PHP array would have to look like this - $json = array ( name => "Bob", children => array (name => "Angie") ) and so on. This is for one of the services that will consume the JSON.
//
// Establish the root.
//
$company = 1;
$query =
"SELECT DISTINCT "
." * "
."FROM "
." tiers "
."WHERE "
." company = {$company} ";
$root = array();
if( $db->query( $query ) )
{
while( ($row = $db->fetchRow()) )
{
$focus = &$root;
for( $i = 1; $i <= 14; $i++ )
{
$name = $row['tier'.$i];
if( !isset( $focus[$name] ) )
{
$focus[$name] = array
(
'name' => $name,
'children' => array(),
);
}
$focus = &$focus[$name]['children'];
}
}
}
$json = JSON_encode( $root );?> -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized.