[FX.php List] JSON help

david weiner 1265 at lucerneblvd.org
Thu Jan 15 16:45:54 MST 2009


Here it is (I've added labels to each section to help you parse out  
which group is what data:

desired array:
Array
(
     [] => Array
         (
             [count] => 3
             [tags] => Array
                 (
                     [meat] => 1
                     [spice] => 1
                     [jewel] => 1
                 )

         )

)

FMP_result:
Array
(
     [data] => Array
         (
             [21.1] => Array
                 (
                     [fragrance] => Array
                         (
                             [0] => bk2
                         )

                     [date_stamp] => Array
                         (
                             [0] => 2009-1-9
                         )

                     [date] => Array
                         (
                             [0] => 01/09/2009
                         )

                     [key] => Array
                         (
                             [0] => 2
                         )

                     [keywords::keyword] => Array
                         (
                             [0] => meat
                             [1] => spice
                             [2] => jewel
                         )

                     [keywords::keywords_key] => Array
                         (
                             [0] => 7
                             [1] => 8
                             [2] => 9
                         )

                     [count_of_keywords] => Array
                         (
                             [0] => 3
                         )

                     [keywords::fragrance_key] => Array
                         (
                             [0] => 2
                         )

                     [keywords::one] => Array
                         (
                             [0] => 1
                         )

                 )

         )

     [linkNext] =>
     [linkPrevious] =>
     [foundCount] => 1
     [fields] => Array
         (
             [0] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => fragrance
                     [type] => TEXT
                     [extra] =>
                 )

             [1] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => date_stamp
                     [type] => TEXT
                     [extra] =>
                 )

             [2] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => date
                     [type] => DATE
                     [extra] =>
                 )

             [3] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => key
                     [type] => NUMBER
                     [extra] =>
                 )

             [4] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => keywords::keyword
                     [type] => TEXT
                     [extra] =>
                 )

             [5] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => keywords::keywords_key
                     [type] => NUMBER
                     [extra] =>
                 )

             [6] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => count_of_keywords
                     [type] => NUMBER
                     [extra] =>
                 )

             [7] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => keywords::fragrance_key
                     [type] => NUMBER
                     [extra] =>
                 )

             [8] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => keywords::one
                     [type] => NUMBER
                     [extra] =>
                 )

         )

     [URL] => http://web:web@10.0.1.201:80/fmi/xml/FMPXMLRESULT.xml?-db=charts&-lay=fragrances&-max=10&key=%3D2&-find
     [query] =>
     [errorCode] => 0
     [valueLists] => Array
         (
         )

)

FMP_k_result:
Array
(
     [data] => Array
         (
             [62.1] => Array
                 (
                     [keywords_key] => Array
                         (
                             [0] => 7
                         )

                     [keyword] => Array
                         (
                             [0] => meat
                         )

                     [fragrance_key] => Array
                         (
                             [0] => 2
                         )

                     [one] => Array
                         (
                             [0] => 1
                         )

                 )

             [63.1] => Array
                 (
                     [keywords_key] => Array
                         (
                             [0] => 8
                         )

                     [keyword] => Array
                         (
                             [0] => spice
                         )

                     [fragrance_key] => Array
                         (
                             [0] => 2
                         )

                     [one] => Array
                         (
                             [0] => 1
                         )

                 )

             [64.1] => Array
                 (
                     [keywords_key] => Array
                         (
                             [0] => 9
                         )

                     [keyword] => Array
                         (
                             [0] => jewel
                         )

                     [fragrance_key] => Array
                         (
                             [0] => 2
                         )

                     [one] => Array
                         (
                             [0] => 1
                         )

                 )

         )

     [linkNext] =>
     [linkPrevious] =>
     [foundCount] => 3
     [fields] => Array
         (
             [0] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => keywords_key
                     [type] => NUMBER
                     [extra] =>
                 )

             [1] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => keyword
                     [type] => TEXT
                     [extra] =>
                 )

             [2] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => fragrance_key
                     [type] => NUMBER
                     [extra] =>
                 )

             [3] => Array
                 (
                     [emptyok] => YES
                     [maxrepeat] => 1
                     [name] => one
                     [type] => NUMBER
                     [extra] =>
                 )

         )

     [URL] => http://web:web@10.0.1.201:80/fmi/xml/FMPXMLRESULT.xml?-db=charts&-lay=keywords&-max=10&fragrance_key=%3D2&-find
     [query] =>
     [errorCode] => 0
     [valueLists] => Array
         (
         )

)

JSON_encode of desiredArray:
{"":{"count":3,"tags":{"meat":"1","spice":"1","jewel":"1"}}}

date stamp:
2009-1-9


On Jan 15, 2009, at 3:37 PM, Dale Bengston wrote:

> Hi David,
>
> Can you do a print_r($FMP_result) and print_r($FMP_k_result) for an  
> example, and post the resulting data that shows up on your screen?
>
> Thanks,
> Dale
>
>
> On Jan 15, 2009, at 5:12 PM, david weiner wrote:
>
>> Thanks so much!
>>
>> I'm getting dangerously close to understanding what's going on, but  
>> there's one element that's just not getting through. I can't get my  
>> date_stamp field to show up in the first array brackets. I've spent  
>> some time reading about key() but I just can't figure out how that  
>> line should be written - I've tried to break it down but I'm just  
>> not getting the concept.
>>
>> I have successfully created the following array:
>> Array
>> (
>>   [] => Array
>>       (
>>           [count] => 3
>>           [tags] => Array
>>               (
>>                   [meat] => 1
>>                   [spice] => 1
>>                   [jewel] => 1
>>               )
>>
>>       )
>>
>> )
>> Using the following code:
>> <?php require_once('Connections/chart.php'); ?>
>> <?php
>> $FMP_find = clone($chart);
>> $FMP_find->layout = 'fragrances';
>> $FMP_findCriterions = array('key'=>'='.$_GET['id'],);
>> foreach($FMP_findCriterions as $key=>$value) {
>>   $FMP_find->AddDBParam($key,$value);
>> }
>>
>> $FMP_k_find = clone($chart);
>> $FMP_k_find->layout = 'keywords';
>> $FMP_k_findCriterions = array('fragrance_key'=>'='.$_GET['id'],);
>> foreach($FMP_k_findCriterions as $key_k=>$value_k) {
>>   $FMP_k_find->AddDBParam($key_k,$value_k);
>> }
>>
>> fmsSetPage($FMP_find,'FMP',10);
>> fmsSetPage($FMP_k_find,'FMP_k',10);
>>
>> $FMP_result = $FMP_find->FMFind();
>> $FMP_k_result = $FMP_k_find->FMFind();
>>
>>
>> $FMP_row = current($FMP_result['data']);
>> $FMP_row_key = key($FMP_result['data']);
>> $FMP_k_row = current($FMP_k_result['data']);
>> $FMP_k_row_key = key($FMP_k_result['data']);
>>
>>
>>
>> foreach( $FMP_k_result['data'] as $FMP_k_row_key=>$FMP_k_row ) {
>> 	$php_tag[$FMP_k_row['keyword'][0]] = $FMP_k_row['one'][0];
>> }
>> foreach( $FMP_result['data'] as $FMP_row_key=>$FMP_row ) {
>> 	$php_count = (int)$FMP_row['count_of_keywords'][0];
>> }
>>
>> $desiredArray[$FMP_result['data'][key($FMP_result['data'])] 
>> [$FMP_row['date_stamp']]] = array(	
>> 	'count' => $php_count,
>> 	'tags' => $php_tag);
>> ?>
>> <pre>
>> <?php print_r($desiredArray) ?></pre>
>> <pre><?php print json_encode($desiredArray); ?></pre>
>> <pre><?php print $FMP_row['date_stamp'][0]; ?></pre>
>>
>>
>>
>> On Jan 15, 2009, at 7:14 AM, Gjermund Gusland Thorsen wrote:
>>
>>> Beware of Thy Array Cowboy™
>>>
>>> ;-p
>>>
>>> 2009/1/15 Jonathan Schwartz <jschwartz at exit445.com>:
>>>> Uh oh.  I'm starting to understand ggt's php shorthand. ;-)
>>>>
>>>> This is a milestone.
>>>>
>>>> J
>>>>
>>>>
>>>>
>>>> At 12:34 PM +0100 1/15/09, Gjermund Gusland Thorsen wrote:
>>>>>
>>>>> I assume what you are looking for would be something along these  
>>>>> lines:
>>>>> ---
>>>>> foreach( $rSlaveTable as $v ) {
>>>>>     $tmp[$v['type'][0]] = $v['value'][0];
>>>>> }
>>>>>
>>>>> $desiredArray[ $rParent['data'][key($rParent['data'])] 
>>>>> ['parent_date'] ] =
>>>>> array(
>>>>>     'count' => $rParent['foundCount'],
>>>>>     'tags' => $tmp;
>>>>> );
>>>>> ---
>>>>> ggt
>>>>>
>>>>> 2009/1/15 Gjermund Gusland Thorsen <ggt667 at gmail.com>:
>>>>>>
>>>>>> In order to make that array, I would have to know your current
>>>>>> Filemaker sources for the fields involved.
>>>>>>
>>>>>> ggt
>>>>>>
>>>>>> 2009/1/15 Blair Duncan <Blair.Duncan at bbdo.ca>:
>>>>>>>
>>>>>>>> From a lurker...
>>>>>>>
>>>>>>> Usually I would sit on my hands rather than replying with a  
>>>>>>> wiseass
>>>>>>> remarks
>>>>>>> such as "and this has something to do with FX/PHP in what  
>>>>>>> way???" as it
>>>>>>> is
>>>>>>> more of a php question.
>>>>>>>
>>>>>>> But then I click on the link and think, wow another cool thing  
>>>>>>> that I
>>>>>>> may be
>>>>>>> able to use someday. Good people on this list, thanks.
>>>>>>>
>>>>>>>
>>>>>>> On 14/01/09 9:38 PM, "david weiner" <1265 at lucerneblvd.org>  
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>> If anyone on the list has any experience getting FX/PHP to  
>>>>>>>> output JSON
>>>>>>>> encoded data (using json_encode) - I'd like to hear from  
>>>>>>>> about it.
>>>>>>>>
>>>>>>>> I'm looking to get filemaker data into JSON for a few reasons,
>>>>>>>> primarily all chart related, and am struggling a little with  
>>>>>>>> the PHP.
>>>>>>>> For one example I'm trying to achieve an array that looks like:
>>>>>>>>
>>>>>>>> [2006-11-01] => Array
>>>>>>>>      (
>>>>>>>>          [count] => 10
>>>>>>>>          [tags] => Array
>>>>>>>>              (
>>>>>>>>                  [web] => 1
>>>>>>>>                  [search] => 1
>>>>>>>>                  [chinese] => 1
>>>>>>>>                  [food] => 1
>>>>>>>>                  [tomatoes] => 1
>>>>>>>>                  [bread] => 1
>>>>>>>>                  [restaurants] => 1
>>>>>>>>                  [japanese] => 1
>>>>>>>>                  [coffee] => 1
>>>>>>>>              )
>>>>>>>>
>>>>>>>>      )
>>>>>>>>
>>>>>>>> where [2006-11-01] = [parent_date]
>>>>>>>> [count] = field[number_of_children_for_parent_date] (portal  
>>>>>>>> rows)
>>>>>>>> [tags] => Array ( ... ) is a loop grabbing all the comma  
>>>>>>>> separated
>>>>>>>> field contents from each portal row for the parent date.
>>>>>>>>
>>>>>>>> The ultimate goal is produce a timecloud using jQuery
>>>>>>>> (http://wiki.github.com/stef/timecloud), but I think if I can  
>>>>>>>> get this
>>>>>>>> figured out, then extending FX to feed all kinds of JSON  
>>>>>>>> driven data
>>>>>>>> visualizers _should_ be doable.
>>>>>>>>
>>>>>>>> I've got some very rough code adapted from the timecloud  
>>>>>>>> delicious
>>>>>>>> sample data and would be happy to share it, but it's  
>>>>>>>> basically not
>>>>>>>> working so I'm leaving it off for now.
>>>>>>>>
>>>>>>>> thanks,
>>>>>>>> David
>>>>>>>> _______________________________________________
>>>>>>>> FX.php_List mailing list
>>>>>>>> FX.php_List at mail.iviking.org
>>>>>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Please consider the environment before printing this e-mail.
>>>>>>>
>>>>>>> This message and any attachments contain information, which  
>>>>>>> may be
>>>>>>> confidential or privileged. If you are not the intended  
>>>>>>> recipient, please
>>>>>>> refrain from any disclosure, copying, distribution or use of  
>>>>>>> this
>>>>>>> information. Please be aware that such actions are prohibited.  
>>>>>>> If you have
>>>>>>> received this transmission in error, kindly notify us by e- 
>>>>>>> mail to
>>>>>>> helpdesk at bbdo.com. We appreciate your cooperation.
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> FX.php_List mailing list
>>>>>>> FX.php_List at mail.iviking.org
>>>>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>>>>
>>>>>>
>>>>> _______________________________________________
>>>>> FX.php_List mailing list
>>>>> FX.php_List at mail.iviking.org
>>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>
>>>>
>>>> --
>>>> Jonathan Schwartz
>>>> Exit 445 Group
>>>> jonathan at exit445.com
>>>> http://www.exit445.com
>>>> 415-370-5011
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



More information about the FX.php_List mailing list