Drupal 7: fetchField(0) giving me half of the records! I am trying to get all the records from one table. I get from the count 18 record, but the actual given lines are 9.

$name = 'admin';
$result = db_query("SELECT name FROM {users} WHERE name &lt;&gt; :name", array(':name' =&gt; $name));
$rownum = $result-&gt;rowCount();
print "This is the total number: ";
print $rownum;
print "&lt;BR&gt;";
foreach ($result as $record) {
  $value = $result-&gt;fetchField(0);
  print $value;
print '&lt;br&gt;';
}


Results:


  This is the total number: 18
  user1
  user2
  user3
  user4
  user5
  user6
  user7
  user8
  user9


Do you think is my loop?
Yes, the loop iterates through result, but additionally you do that kind of again in your line $value = $result-&gt;fetchField(0);.

This should be changed to $value = $record-&gt;name;.