Re: [PHP] Thinking out loud - a continuation...

2012-04-02 Thread Jay Blanchard
[snip] function getTiersJson( $company ) { $tiers = getTiers( $company ); $json = JSON_encode( $tiers ); } $tiersJson = getTiersJson( 1 ); ? This will output JSON with the following structure: [/snip] OK, now I know I am being dense - but don't I have to add return $json; to

Re: [PHP] Thinking out loud - a continuation...

2012-04-02 Thread Matijn Woudt
On Mon, Apr 2, 2012 at 10:36 PM, Jay Blanchard jay.blanch...@sigmaphinothing.org wrote: [snip] function getTiersJson( $company ) {    $tiers = getTiers( $company );    $json = JSON_encode( $tiers ); } $tiersJson = getTiersJson( 1 ); ? This will output JSON with the following structure:

Re: [PHP] Thinking out loud - a continuation...

2012-04-02 Thread Robert Cummings
On 12-04-02 04:36 PM, Jay Blanchard wrote: [snip] function getTiersJson( $company ) { $tiers = getTiers( $company ); $json = JSON_encode( $tiers ); } $tiersJson = getTiersJson( 1 ); ? This will output JSON with the following structure: [/snip] OK, now I know I am being dense - but

Re: [PHP] Thinking out loud - a continuation...

2012-03-31 Thread Jay Blanchard
[snip] On 3/30/2012 1:14 PM, Robert Cummings wrote: On 12-03-27 11:11 AM, Jay Blanchard wrote: [snip]On 3/27/2012 12:21 AM, Robert Cummings wrote: [-- SNIP --] Essentially, entries at the root and entries for the children are just auto indexed array items but the actual entries in those

Re: [PHP] Thinking out loud - a continuation...

2012-03-30 Thread Robert Cummings
On 12-03-27 11:11 AM, Jay Blanchard wrote: [snip]On 3/27/2012 12:21 AM, Robert Cummings wrote: [-- SNIP --] Essentially, entries at the root and entries for the children are just auto indexed array items but the actual entries in those arrays retain the associative index structure for

Re: [PHP] Thinking out loud - a continuation...

2012-03-27 Thread Jay Blanchard
[snip]On 3/27/2012 12:21 AM, Robert Cummings wrote: I think you need two things... the recursive post processor that removes the string indexes for the children. And then a function that creates a JavaScript array expression from an object or array. The question I have for you... is given the

Re: [PHP] Thinking out loud - a continuation...

2012-03-27 Thread Jay Blanchard
[snip]On 3/27/2012 12:21 AM, Robert Cummings wrote: I think you need two things... the recursive post processor that removes the string indexes for the children. And then a function that creates a JavaScript array expression from an object or array. The question I have for you... is given the

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Jay Blanchard
[snip] This is one of those projects. It is apparently going to be trying every step of the way. [/snip] I was proven right this morning after all of Robert's good work and what I had added to make this work. It turns out that the one service who was anxious to consume the JSON output expects

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Stuart Dallas
On 26 Mar 2012, at 19:12, Jay Blanchard wrote: [snip] This is one of those projects. It is apparently going to be trying every step of the way. [/snip] I was proven right this morning after all of Robert's good work and what I had added to make this work. It turns out that the one

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Jay Blanchard
[snip] Square brackets in JSON represent arrays. Take their JSON, run it through json_decode, and assuming it decodes correctly compare the structure to what you already have. You should then be able to modify what you have so it generates JSON in the format they are expecting. [/snip]

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Robert Cummings
On 12-03-26 02:12 PM, Jay Blanchard wrote: [snip] This is one of those projects. It is apparently going to be trying every step of the way. [/snip] I was proven right this morning after all of Robert's good work and what I had added to make this work. It turns out that the one service who

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Jay Blanchard
[snip] *lol* No worries... it's all about solving problems :) [/snip] the other folks who needed to consume the JSON have all done so successfully today - just this one. The guy who runs it was plenty arrogant when I discussed with him. He is the one who wanted me to remove the extra array

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Robert Cummings
On 12-03-26 05:14 PM, Jay Blanchard wrote: [snip] *lol* No worries... it's all about solving problems :) [/snip] the other folks who needed to consume the JSON have all done so successfully today - just this one. The guy who runs it was plenty arrogant when I discussed with him. He is the

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Jay Blanchard
[snip] Did you end up with a satisfactory output? It's not overly difficult to generate an array instead of an object. [/snip] I did for all but this one instance. Are you saying that it would be easy to make of the children arrays? I thought they were already - am I missing something? --

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Robert Cummings
On 12-03-26 06:52 PM, Jay Blanchard wrote: [snip] Did you end up with a satisfactory output? It's not overly difficult to generate an array instead of an object. [/snip] I did for all but this one instance. Are you saying that it would be easy to make of the children arrays? I thought they

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Jay Blanchard
[snip] On Mar 26, 2012, at 5:58 PM, Robert Cummings wrote: On 12-03-26 06:52 PM, Jay Blanchard wrote: [snip] Did you end up with a satisfactory output? It's not overly difficult to generate an array instead of an object. [/snip] I did for all but this one instance. Are you saying that it

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Robert Cummings
On 12-03-26 07:05 PM, Jay Blanchard wrote: [snip] On Mar 26, 2012, at 5:58 PM, Robert Cummings wrote: On 12-03-26 06:52 PM, Jay Blanchard wrote: [snip] Did you end up with a satisfactory output? It's not overly difficult to generate an array instead of an object. [/snip] I did for all but

Re: [PHP] Thinking out loud - a continuation...

2012-03-25 Thread Jay Blanchard
[snip] a necessary part of building the structure. It can be removed but only as a post process. Why does it have to be removed? You can loop through the structure in JavaScript without paying heed to the key's value. If it absolutely must go... you need to recurse through the final structure

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Jay Blanchard
[snip] Did you send me a sample dump for your table :) [/snip] I'll do that today. I got side-tracked last night. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Jay Blanchard
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

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread tamouse mailing lists
On Sat, Mar 24, 2012 at 7:41 AM, Jay Blanchard jay.blanch...@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

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Robert Cummings
On 12-03-24 08:41 AM, Jay Blanchard 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

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Jay Blanchard
[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

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Robert Cummings
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,

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Jay Blanchard
[snip] A little tweak here... a little tweak there: [/snip] if( !isset( $focus[$name] ) ) { $focus[$name] = array ( 'name' = $name, 'children' = array(),

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Jay Blanchard
[snip] A little tweak here... a little tweak there: [/snip] One more little tweak may be required. The JSON looks like this {Executives and Management:{name:Executives and Management,children:{ The first part {Executives and Management: needs to be removed. I think I know what to do. --

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Jay Blanchard
[snip] One more little tweak may be required. The JSON looks like this {Executives and Management:{name:Executives and Management,children:{ The first part {Executives and Management: needs to be removed. I think I know what to do. [/snip] It has become painfully obvious that I do not

Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Robert Cummings
On 12-03-24 04:11 PM, Jay Blanchard wrote: [snip] One more little tweak may be required. The JSON looks like this {Executives and Management:{name:Executives and Management,children:{ The first part {Executives and Management: needs to be removed. I think I know what to do. [/snip] It has

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] Your data structure doesn't appear to be very ummm normalized... Nonetheless, the following should do it: [/snip] You're absolutely correct. Unfortunately I am not the designer and cannot really do anything about it. I just have to work with what I have. Thank you very much for this -

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings
On 12-03-23 02:08 PM, Jay Blanchard wrote: [snip] Your data structure doesn't appear to be very ummm normalized... Nonetheless, the following should do it: [/snip] You're absolutely correct. Unfortunately I am not the designer and cannot really do anything about it. I just have to work with

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] $json = JSON_encode( $root ); [/snip] Update on my test. This works perfectly Robert - thank you very much! But there is one small problem that I am trouble-shooting: it only goes one layer and doesn't progress any further. I suspect it is on this section of code that I am going to

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] $json = JSON_encode( $root ); [/snip] Update on my test. This works perfectly Robert - thank you very much! But there is one small problem that I am trouble-shooting: it only goes one layer and doesn't progress any further. I suspect it is on this section of code that I am

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings
On 12-03-23 03:17 PM, Jay Blanchard wrote: [snip] $json = JSON_encode( $root ); [/snip] Update on my test. This works perfectly Robert - thank you very much! But there is one small problem that I am trouble-shooting: it only goes one layer and doesn't progress any further. I suspect it

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings
On 12-03-23 03:22 PM, Jay Blanchard wrote: [snip] $json = JSON_encode( $root ); [/snip] Update on my test. This works perfectly Robert - thank you very much! But there is one small problem that I am trouble-shooting: it only goes one layer and doesn't progress any further. I suspect it

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
On Mar 23, 2012, at 2:25 PM, Robert Cummings wrote: On 12-03-23 03:17 PM, Jay Blanchard wrote: [snip] $json = JSON_encode( $root ); [/snip] Update on my test. This works perfectly Robert - thank you very much! But there is one small problem that I am trouble-shooting: it only goes

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings
On 12-03-23 03:28 PM, Jay Blanchard wrote: On Mar 23, 2012, at 2:25 PM, Robert Cummings wrote: On 12-03-23 03:17 PM, Jay Blanchard wrote: [snip] $json = JSON_encode( $root ); [/snip] Update on my test. This works perfectly Robert - thank you very much! But there is one small problem

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] Did you get any results form the database on the second run through the query loop? [/snip] Actually, no. I just ran the raw query - SELECT DISTINCT `TIER3DATA` AS id, `TIER2DATA` AS parentId FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `TIER2DATA` IN ('Executives and

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] No, I'm performing assignment... intentionally. Parent's becomes the previous children to move down a level. The following: if( !($parents = $children) ) performs assignment and an empty array check in one statement. [/snip] Gotcha'. So all I am ever getting back right now is

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] SELECT DISTINCT `TIER3DATA` AS id, `TIER2DATA` AS parentId FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `TIER2DATA` IN ('Executives and Management','Professionals','Technicians','Craft Workers-Skilled','Operatives','Contractor','Sales Workers','Laborers and Helpers','Admin

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings
On 12-03-23 03:52 PM, Jay Blanchard wrote: [snip] SELECT DISTINCT `TIER3DATA` AS id, `TIER2DATA` AS parentId FROM `POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `TIER2DATA` IN ('Executives and Management','Professionals','Technicians','Craft Workers-Skilled','Operatives','Contractor','Sales

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] $item['children'] should be an array, somehow a string has been assigned :/ [/snip] Yep. I am trying to figure that out now. I'm sure it is something really small. BTW, after making the change to the for loop there are results returned as we expected. -- PHP General Mailing List

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] $item['children'] should be an array, somehow a string has been assigned :/ [/snip] Yep. I am trying to figure that out now. I'm sure it is something really small. [/snip] I have been hammering away at it for a while now and still cannot find the issue. I'll push away for a while

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Jay Blanchard
[snip] …stuff…. [/snip] For those interested here is where the problem seems to occur - $child = array ( 'id' = $id, 'parentId' = $pid, 'children' = array() );

Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings
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

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Bastien
On 2012-03-21, at 2:39 PM, Jay Blanchard jay.blanch...@sigmaphinothing.org wrote: This is a continuation of the nested query thing I posted to the list a while back. I was finally able to output a nested unordered array that worked out well, but scope-creep has come in the door and I have

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Jay Blanchard
[snip] Would it not be easier to get the data from a view which has the tables joined? Then it would be one query and it's a simple matter to format the results into the multi dimensional array then json? [/snip] The data is all from one table. I'll write up a more thorough explanation in a

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Tedd Sperling
On Mar 21, 2012, at 3:45 PM, Daniel Brown wrote: I would, yes, but that's not the point. Is Anna single? I'm ready to trade Debs in for a newer model. -- /Daniel P. Brown Ah... to be young again. But, on the other hand, they have so much to learn. :-) Cheers, tedd

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Jay Blanchard
[snip] ...stuff... [/snip] Here is the explanation for what I have done and what I am trying to do - (based on the customer's request). A week or so ago I took a set of queries from one table and made them into an unordered list. This will be pseudo-code so that you get idea. SELECT

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings
On 12-03-22 11:28 AM, Jay Blanchard wrote: [snip] ...stuff... [/snip] Here is the explanation for what I have done and what I am trying to do - (based on the customer's request). A week or so ago I took a set of queries from one table and made them into an unordered list. This will be

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Jay Blanchard
[snip] Fix this code... I've come across codebases that did this specific type of nested querying and it resulted in 1 queries to the database on every page. Instead, create a layered approach: 1. Select your root elements. 2. Loop over in PHP and create an array of child IDs.

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings
On 12-03-22 11:58 AM, Jay Blanchard wrote: [snip] Fix this code... I've come across codebases that did this specific type of nested querying and it resulted in 1 queries to the database on every page. Instead, create a layered approach: 1. Select your root elements. 2. Loop over

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings
On 12-03-22 11:58 AM, Jay Blanchard wrote: [snip] Fix this code... I've come across codebases that did this specific type of nested querying and it resulted in 1 queries to the database on every page. Instead, create a layered approach: 1. Select your root elements. 2. Loop over

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Jay Blanchard
[snip] On 3/22/2012 11:17 AM, Robert Cummings wrote: On 12-03-22 11:58 AM, Jay Blanchard wrote: [snip] Fix this code... I've come across codebases that did this specific type of nested querying and it resulted in 1 queries to the database on every page. Instead, create a layered approach:

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Jay Blanchard
[snip] Sorry, I just realized I didn't make the optimization explicitly obvious... when I say Select the children I mean to select them using an IN( id1, id2, id3 ) clause instead of a query for each. This is why we build the array of parent IDs (also I wrote build an array of child IDs, it

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings
On 12-03-22 12:34 PM, Jay Blanchard wrote: [snip] Sorry, I just realized I didn't make the optimization explicitly obvious... when I say Select the children I mean to select them using an IN( id1, id2, id3 ) clause instead of a query for each. This is why we build the array of parent IDs (also

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Jay Blanchard
On 3/22/2012 11:40 AM, Robert Cummings wrote: On 12-03-22 12:34 PM, Jay Blanchard wrote: [snip] Sorry, I just realized I didn't make the optimization explicitly obvious... when I say Select the children I mean to select them using an IN( id1, id2, id3 ) clause instead of a query for each. This

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings
On 12-03-22 01:06 PM, Jay Blanchard wrote: On 3/22/2012 11:40 AM, Robert Cummings wrote: What's the field for which you are selecting data? I've written this up as a parent/child relationship but it works for data/sub-data relationships also. SELECT itemId, otherData FROM table WHERE some

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Jay Blanchard
[snip] At one point you indicated all the data was coming from one table. Can you send me the table fields and indicate which fields are used to determine parent child relationship? Also 2 sample rows of data which have a relationship would be helpful. [/snip] Columns - tier1, tier2,

Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings
On 12-03-22 03:54 PM, Jay Blanchard wrote: [snip] At one point you indicated all the data was coming from one table. Can you send me the table fields and indicate which fields are used to determine parent child relationship? Also 2 sample rows of data which have a relationship would be

Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Adam Richardson
On Wed, Mar 21, 2012 at 2:39 PM, Jay Blanchard jay.blanch...@sigmaphinothing.org wrote: ... I have a project where I have multiple queries and each query uses the results from the previous query to get it's results. I need to do one of two things, either out put a multidimensional array that

Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Daniel Brown
On Wed, Mar 21, 2012 at 14:39, Jay Blanchard jay.blanch...@sigmaphinothing.org wrote: [snip!] I ran it through json_encode() and got the following output

Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Jay Blanchard
[snip] I would, yes, but that's not the point. Is Anna single? I'm ready to trade Debs in for a newer model. [/snip] I'm thinking that Debs would upset your array if you traded her in. Anyhow, I have spent the last hour trying to output valid JSON but the whole thing is making me

Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Robert Cummings
On 12-03-21 03:52 PM, Jay Blanchard wrote: [snip] I would, yes, but that's not the point. Is Anna single? I'm ready to trade Debs in for a newer model. [/snip] I'm thinking that Debs would upset your array if you traded her in. Anyhow, I have spent the last hour trying to output valid

Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Jay Blanchard
[snip] Why are you trying to create the JSON structure in parts? When I have nesting like this i build the full nested structure as PHP, then export to JSON. [/snip] As PHP? An array? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Jim Lucas
On 03/21/2012 11:39 AM, Jay Blanchard wrote: If you were me would you just generate the JSON? If not what is he best way to output an array that will nest properly for each subsequent query? Depends on where the data is coming from and how you are retrieving it from. Can you provide

Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Robert Cummings
On 12-03-21 04:42 PM, Jay Blanchard wrote: [snip] Why are you trying to create the JSON structure in parts? When I have nesting like this i build the full nested structure as PHP, then export to JSON. [/snip] As PHP? An array? Yeah sorry... you know what I meant ;) Cheers, Rob. -- E-Mail