View Single Post
  #2  
Old 10-29-2007, 01:34 PM
Eric Santiago
Guest
 
Posts: n/a
Multiple objects

This is great. I was working on my own method for outputting the values from a given query without explicitly naming the fields. However, I'd like to include values from any given reference fields as well. For example, SELECT Id, firstname, Account.Name from Contact WHERE LastName Like 'Y%'.

This is a part of what I've come up with to handle that.

PHP Code:
foreach ($returns as $r) {
        
$output .= '<tr>';
    
$r = new SObject($r);                                
    
//loop through all feilds and return values,
    
$field_ary['id'] = $r->Id;
    
//does not work for ID, and reference feilds, ie Account Name
    
foreach($r->fields as $key => $value) {
        
$field_ary[strtolower($key)]=$value;
    }
    if (
$r->sobjects) { //loop through related object and return fields, ie Account Name
          
foreach($r->sobjects as $s) {
          
$c 0;
                foreach(
$r->sobjects[$c]->fields as $key => $value) {
            
$field_ary[strtolower($key)]=$value;
        }
          
$c += 1;
          }
    }
    foreach(
$field_ary as $key => $value) {
      
$output .= '<td>'.$value.'</td>';
    }
        
$output .= '</tr>';

This works, but what I'd like to do is return the values in a table where the column order is the same as the order that they appear in the query. As I have it written ID will always be in the first column and any referenced fields (ie Account.Name) are processed last. Do you have any suggestions on how this might be accomplished?
Reply With Quote