Park Productions Park Productions - 1 year ago 96
JSON Question

Filemaker php api: encode for each loop variables to json

I've been asked to provide filemaker data as json objects through the filemaker php api.

I've been able to use the following on a single record

echo json_encode(array($namefamily, $namefirst, $dob, ));

Now I need to encode to json in my for each loop - not sure how to get it to work with concatenated variables in:

$records = $result->getRecords();
foreach($records as $record){
echo' ' . $record->getField('NameFirst') . ' | ' . $record->getField('NameFamily') .' ';

Answer Source

Similar to previous answer, but using working FileMaker API syntax...

$records = $result->getRecords();

foreach($records as $record){
    $data[] = array( 
                    'NameFirst' => $record->getField("NameFirst"),
                    'NameFamily' => $record->getField("NameFamily")

echo json_encode($data);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download