On 12-03-24 01:09 PM, Jay Blanchard wrote:
[snip]The crux of it is:

    $focus =&$focus[$name];
[/snip]

It 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

{
    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.

A little tweak here... a little tweak there:

<?php

    //
    // 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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to