4

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')
  ->fields('r')
  ->execute()
  ->fetchAll();

  dpm($result);

1 Answer 1

4
<?php
// Retrieve all records into an indexed array of stdClass objects.
$info = $result->fetchAll();

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

To iterate just use:

foreach($info as $key => $object) {
  print $object->property . "<br>";
}

References:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.