How to iterate through an object returned by fetchAll? Since fetchAssoc was returning only one row, i was forced to use fetchAll.

The problem is fetchAll returns the data as an array of objects. Iterating through them is kind of painful, not impossible but seems like a long way to go for something that should be really simple.

fetchAllAssoc throws an error.

If somebody could show me a neater trick, that would be great.

    $result = db_select('raffles', 'r')
  -&gt;fields('r')
  -&gt;execute()
  -&gt;fetchAll();

  dpm($result);
&lt;?php
// Retrieve all records into an indexed array of stdClass objects.
$info = $result-&gt;fetchAll();

// Retrieve all records into an associative array
// keyed by the field in the result specified.
$info = $result-&gt;fetchAllAssoc($field)


To iterate just use:

foreach($info as $key =&gt; $object) {
  print $object-&gt;property . "&lt;br&gt;";
}


References:

https://www.drupal.org/node/1251174