Processing getRecords with foreach loop in PHP API

Discussion created by jgill@occu-med.com on Jan 23, 2014
Latest reply on Jan 23, 2014 by jgill@occu-med.com



I'm fairly new to PHP so I'm pretty sure I'm missing something easy here. I have a query that is returning 3 records that I want to loop through with a foreach loop and pull contents for each record from a particular field. After reading through the API, it sounds like they want you to assign the results to an array with the getRecords() method and then loop through the records with foreach loop. (At least that's what the API says...)


Anyway, I have a simple query set up below:

$fm = new FileMaker();

$query = $fm->newFindAllCommand('myLayout');

$result = $query->execute();

$records = $result->getRecords();

$foundSet = $result->getFoundSetCount();

$fields = $result->getFields; echo '<p>Records Found: ' .$foundSet.'</br>'; <-- Returns 3 (the correct found set)

foreach ($records as $record) {

echo $record->getField('login').'</br>';


I can see that the $foundset & $fields variables contain the correct properties of the records for my found set, but when I go to loop through the records as outlined in th APU guide, the getField method returns the first record of the found set 3 times. I must be calling it incorrectly, but does anybody have any clue what I'm doing wrong?