Iterate Over Drupal DB Result Set

Last modified: 
Sunday, March 29th, 2015

How to loop over a DB Result set in Drupal 6

$uid = 1;
$result = db_query("SELECT n.nid, n.title, n.created
                             FROM {node} n 
                             WHERE n.uid = %d", $uid);
while ($record = db_fetch_object($result)) {
  // Perform operations on $record->title, etc. here.
}


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.