1

I have the table where I store uid column. I want to get all the values from that table, but I only get the frist element.

My query:

$sql = db_select('voting_nomination_counter', 'v')
->fields('v', array('uid'))
->execute()
->fetchAssoc();

Where is my problem?

9

DatabaseStatementBase::fetchAssoc fetches the next row and returns it as an associative array.

$query = db_select('voting_nomination_counter', 'v');
$query->fields('v',array('uid'));
$result = $query->execute();
while($record = $result->fetchAssoc()) {
  print_r($record);
}
| improve this answer | |
5

check with this

 $query = db_select('voting_nomination_counter','v');
 $query->fields('v');
 $results=$query->execute()->fetchAll();
 print_r($results);
| improve this answer | |
0

You may use this for fetching all records. Remove condition if you don't want to add.

<?php
    $query = db_select('data');
    $query->fields('data', array('LivingArea', 'Postalcode', 'Street'));
    $query->condition('Postalcode', $postalcode);
    $result = $query->execute()->fetch();
    drupal_set_message($result->street);
    drupal_set_message($result->livingarea);
?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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