Re: Thinking out loud - a continuation...

From: Date: Sat, 24 Mar 2012 14:43:41 +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-317247@lists.php.net to get a copy of this message
On Sat, Mar 24, 2012 at 7:41 AM, Jay Blanchard <jay.blanchard@sigmaphinothing.org> wrote: > > On Mar 23, 2012, at 11:24 PM, Robert Cummings wrote: > >> 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. >> -- > > At first blush I'm not sure how this would work - but I haven't had any coffee yet > either. I'll give this a shot in a little while. Seems almost too easy. > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > This has been fascinating to read. I hope you get it figured out, Jay!

« previous php.general (#317247) next »