How to obtain contents from a drupal 7 query?
execute() returns a resource you can iterate over in a foreach loop, e.g: 

foreach ($result as $record) {
  $office_id = $record-&gt;office_id;
}


In your case you probably want to use the fetchObject() method to actually retrieve the first record returned from the query:

$result = $query-&gt;execute()-&gt;fetchObject();
$office = $result-&gt;office_id;