I have just started using Drupal 7 and db_select()
.
if I have a result from db_select()
(e.g. $result = $query->execute()
, why can I only loop through this result once?
It appears as if there is a cursor that is not reset following a foreach loop.
So I tried to find a function that would convert this result into a multi dimensional array (e.g. $result = $result->fetchAllAssoc()
) but I have found nothing.
Instead, at the moment I have to loop through the result to create an array of row objects to use later through the code (if i need to loop through it more than once)
/* this returns an array of row objects that you can use like any other array but seems as though there should be an API function to do this for me as part of the database class ? */
$array = array();
foreach($result as $row) {
$array[] = $row;
}
Surely there must be an API function to do this already.