function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KnewTVKnewTV 

PHP Relationship Query Results

I have a query that when I print with the following.....

<?php    print_r($record); ?>
I get....

Array ( [rie__Session__r] => sObject Object ( [type] => rie__Session__c [id] => [values] => Array ( [Name] => Forum M-22: 3-D Flash [rie__Session_Abstract__c] => Test Description ) [fieldsToNull] => ) [Name] => Shawn Adams [rie__Session__c] => a0Ro0000006Q1uJEAS )

This works fine...
<?php  echo   $record['Name']?>
I get... Shawn Adams

Neither of these work...
<?php  echo  $record[rie__Session__c.Name]  ?>
<?php  echo  $record[rie__Session__r.Name]  ?>
<?php  echo  $record->sobjects[0]->values->rie__Session__c->Name;  ?>

Any suggestions?

Thanks
 
Best Answer chosen by KnewTV
James LoghryJames Loghry

It's been a long time since I've dabbled in PHP, but I believe you need something like the following:

 

<?php  echo  $record['rie__Session__r']->values['Name'];  ?>

Or
 
<?php  echo  $record['rie__Session__r']['values']['Name'];  ?>

Basically speaking, record is an array of fields, containing a key "rie__Session__r".  "rie__Session__r" is an object, and contains a key called "values" which contains all the fields to print off, inlcuding the name of the rie__Session__r record.
 

All Answers

James LoghryJames Loghry

It's been a long time since I've dabbled in PHP, but I believe you need something like the following:

 

<?php  echo  $record['rie__Session__r']->values['Name'];  ?>

Or
 
<?php  echo  $record['rie__Session__r']['values']['Name'];  ?>

Basically speaking, record is an array of fields, containing a key "rie__Session__r".  "rie__Session__r" is an object, and contains a key called "values" which contains all the fields to print off, inlcuding the name of the rie__Session__r record.
 
This was selected as the best answer
KnewTVKnewTV
Hi James,

Thi one owrks...

       echo  $record['rie__Session__r']->values['Name']; 

Thanks!!!
KnewTVKnewTV
Took this one more level... This works too...

<?php  echo   $record['rie__Contact_Name__r']->values['Account']->values['Name']?>