Re: Thinking out loud - a continuation...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12-03-23 05:41 PM, Jay Blanchard wrote:
[-- DELETED GARBAGE --]  :)

I just realized... I've been stuck in a thinking rut. I latched onto one solution that works well in some case but didn't fully examine the nuances of your own scenario. Given the way you are creating your hierarchy you will ultimately retrieve all rows. As such the following simple solution will do what you need:

<?php

    $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();
                }

                $focus = &$focus[$name];
            }
        }
    }

    $json = JSON_encode( $root );

?>

Cheers,
Rob.
--
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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux