Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5615 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies
Posted

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 .="&copyR=".$rows4;

$userData .="&recId=".$recDBCN;

print $userData;

?>

Posted

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');

}

This topic is 5615 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.