[FX.php List] JSON help
Dale Bengston
dbengston at tds.net
Thu Jan 15 19:59:11 MST 2009
All right!
Dale
On Jan 15, 2009, at 7:45 PM, david weiner wrote:
> I think I figured it out - I haven't tested the actual code -> chart
> part yet, but I figured out the array part (and I cleaned up the
> rest of my page that I had messed up along the way)
>
> the trick, if I have this right, was I first needed to create an
> array for my date, then I could use that array key for my nested
> array (or whatever you call this structure).
>
> so here's the code as I have it now, I'm going to see if I can get
> this into timecloud data and will post a complete solution for
> anyone interested.
>
> thanks,
> david
>
> here's the rendered page:
> desired array: Array
> (
> [2009-1-2] => Array
> (
> [count] => 6
> [tags] => Array
> (
> [fruit] => 1
> [spice] => 1
> [nice] => 1
> [rice] => 1
> [lice] => 1
> [dice] => 1
> )
>
> )
>
> )
>
> JSON_encode of desiredArray:
> {"2009-1-2":{"count":6,"tags":
> {"fruit
> ":"1","spice":"1","nice":"1","rice":"1","lice":"1","dice":"1"}}}
>
>
> and here's the php page:
> <?php require_once('Connections/chart.php'); ?>
> <?php
> $FMP_find = clone($chart);
> $FMP_find->layout = 'fragrances';
> $FMP_findCriterions = array('key'=>'=='.fmsEscape($_REQUEST['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'=>'=='.fmsEscape($_REQUEST['id']),);
> foreach($FMP_k_findCriterions as $key_k=>$value_k) {
> $FMP_k_find->AddDBParam($key_k,$value_k);
> }
>
> fmsSetPage($FMP_find,'FMP',100);
> fmsSetPage($FMP_k_find,'FMP_k',100);
>
> $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];
> }
> $datearray = array(
> $FMP_row['date_stamp'][0] => $mydate
> );
> $desiredArray[key($datearray)] = array(
> 'count' => $php_count,
> 'tags' => $php_tag);
> ?>
> <pre>
> desired array: <?php print_r($desiredArray) ?></pre><br />
> JSON_encode of desiredArray: <pre><?php print
> json_encode($desiredArray); ?></pre><br />
>
>
>
> 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
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1582 bytes
Desc: not available
Url : http://mail.iviking.org/pipermail/fx.php_list/attachments/20090115/9be3ba62/smime.bin
More information about the FX.php_List
mailing list