July 8, 200916 yr Newbies I'm sure this is simple, but for some reason I am stuck: I am trying to get records from one layout, then use the info to get the record ID from another layout. I get the records from the first layout fine, but it stops working at the second getRecords() request? Did I need to reset the DB to all records or something else....I;m not entirely used to how FM interacts with PHP. Here is my code: ... $fm = new FileMaker(FM_FILE, FM_HOST, FM_USER, FM_PASS); $test = $_POST['test']; $COPY_LOCATIONID = $test; $request = $fm->newFindCommand('COPY'); $request->addFindCriterion( 'COPY_LOCATIONID', $COPY_LOCATIONID); $result = $request->execute(); $records = $result->getRecords(); $rows = ''; foreach ($records as $record) { $rows .=$record->getField('ITEM::title'); } $rows2 = ''; foreach ($records as $record) { $rows2 .=$record->getField('CREATOR::creator'); } $rows3 = ''; foreach ($records as $record) { $rows3 .=$record->getField('PUBLISHER::publisher'); } $rows4 = ''; foreach ($records as $record) { $rows4 .=$record->getField('ITEM::issued'); } $recDBCN = ''; foreach ($records as $record) { $recDBCN .=$record->getField('ITEM::identifier'); } $fm2 = new FileMaker(FM_FILE, FM_HOST, FM_USER, FM_PASS); $request2 =$fm2->newFindCommand('ITEM'); $request2->addFindCriterion('identifier', $recDBCN); $result2 = $request2->execute(); $records2 = $result2->getRecords(); //$recId = ''; //foreach ($records as $record) { //$recId .=$record->getRecordId(); //} $userData ="bookTi=".$rows; $userData .="&bookAu=".$rows2; $userData .="&bookPub=".$rows3; $userData .="©R=".$rows4; $userData .="&recId=".$recDBCN; print $userData; ?>
July 8, 200916 yr Make sure the layout you are using has on it all the fields that you want to access. Hope that helps. James
July 9, 200916 yr First, you need to add error checking after both of your $request->execute() calls. This should tell you what is going on. $result = $request->execute(); if (FileMaker::isError($result)) { echo 'Error: (' . $result->getCode() . ') ' . $result->getMessage() . "n"; exit; } $records = $result->getRecords(); and $result2 = $request2->execute(); if (FileMaker::isError($result2)) { echo 'Error: (' . $result2->getCode() . ') ' . $result2->getMessage() . "n"; exit; } $records2 = $result2->getRecords(); Second, I'm not sure what you're going for by concatenating all of a field's values across the returned record set to a single string. If your query is designed to always return one and only one record you can access the record this way $records = $result->getRecords(); $title = $records[0]->getField('ITEM::title'); If you do need to loop through the records there's no need to do it more than once $rows = ''; $rows2 = ''; $rows3 = ''; $rows4 = ''; $recDBCN = ''; foreach ($records as $record) { $rows .= $rows2 .=$record->getField('CREATOR::creator'); $rows3 .=$record->getField('PUBLISHER::publisher'); $rows4 .=$record->getField('ITEM::issued'); $recDBCN .=$record->getField('ITEM::identifier'); }
Create an account or sign in to comment