require_once ('FileMaker.php');
$fm = new FileMaker('MyDatabase');
$fm->setProperty('hostspec', 'http://MyFMServer');
$fm->setProperty('username', 'MyAdminUserName');
$fm->setProperty('password', 'MyAdminPassword');
$findCommand =& $fm->newFindCommand('MyMainLayoutName');
$findCommand->addFindCriterion('MySearchField', $_GET['MySearchString'] );
$findCommand->addSortRule('MySortField',1, FILEMAKER_SORT_ASCEND );
$result = $findCommand->execute();
//If an error is found, return a message and exit.
if (FileMaker::isError($result)) {
printf("Error %s: %s\n", $result->getCode());
"<br>";
printf($result->getMessage());
exit;
}
$records = $result->getRecords(); //Get the records
//Show me the related sets available for the result...just so I can see what is available
$relatedSets = $result->getRelatedSets();
if( FileMaker::isError($relatedSets) ){
printf("Error %s: %s\n", $relatedSets->getCode());
"<br>";
printf( $relatedSets->getMessage( ) );
exit;
} else{
echo "<pre>\n";
print_r( $relatedSets ); //This shoes that 'RelatedSetName' is available as a related set
echo "</pre>\n";
}
$record_count = 0; //Start record counter
$mydata = array(); //Create holding array for formatted data
foreach($records as $record){
$flds = $record->getFields();
$mydata[$record_count]['record_id'] = $record->getRecordId();
foreach($flds as $field_name){ //I loop through all available fields and buid a simple array
$mydata[$record_count][$field_name] = $record->getField($field_name);
}
//Try to get related records
if( $record_count == 0){ //I only want to get related records on the first pass
//Establish a holding location for related records
$mydata['RelatedRecords'] = array();//Establish the array element so that it shows up regardless of success
$relatedRecs = $record->getRelatedSet( "RelatedSetName" );
if( !FileMaker::isError($relatedRecs) ){
foreach($relatedRecs as $relatedRec){
$relRecords = array();
$relRecords['record_id'] = $relatedRec->getRecordId();
$relRecords_fields = $relatedRec->getFields();
foreach($relRecords_fields as $relRecords_field){//loop through related set fields and build another simple array
$relRecords[$relRecords_field] = $relatedRec->getField( $relRecords_field );
}
$mydata['RelatedRecords'][ $relRecords['record_id'] ] = $relRecords;
}
} else{
printf("Error %s: %s\n", $relatedRecs->getCode());
"<br>";
printf($relatedRecs->getMessage()); //This says that 'RelatedSetName' is not present ???
exit;
}
}
$record_count++;
}
//Show me what we have accomplished
echo "<pre>\n";
print_r( $mydata ); //This displays the formatted data array from my primary search, including the empty 'RelatedRecords' element
echo "</pre>\n";
Ahh...thanks for the Code Tag info...I don't post in forums often.
Here is what I am wanting to do. The FM application I am using as a datasource is a custom manufacturing information system ( MIS ) for a production plant. The plant receives orders from customers. The orders are broken down into separate production operations that we call Parts. For example, if we receive an order for 10,000 widgets ( order number ExampleA ) and each widget requires four separate production processes there will be four records in our MIS that contain, or are linked to, relevant production information. The parts would be enumerated thusly: ExampleA-1, ExampleA-2, ExampleA-3, and ExampleA-4. These four records are fetched in the primary records loop in my PHP code.
In relation to the part records there are also shipment records. Once we have manufactured the 10,000 widgets via their four step production process we need to ship them to various locations as directed by the customer. There may be as few as one related shipment record or they may number in the hundreds.
I only need to grab the shipment records once, for the work order as a whole. This is why in my PHP code I only have the getRelated method being called once when my generic record_counter is zero.
I hope I am making sense with all this.
Thanks for any advise in advance.