How to iterate over all the nodes from a content type
Drupal core provides a class called EntityFieldQuery().  There is also a handy document page for using it, that has lots of examples.  In its simplest form:

$query = new EntityFieldQuery();

$query-&gt;entityCondition('entity_type', 'node')
  -&gt;entityCondition('bundle', 'page')
  -&gt;propertyCondition('status', 1);

$result = $query-&gt;execute();

if (!empty($result['node'])) {
  $nids = array_keys($result['node']);
  $nodes = node_load_multiple($nids);

  foreach ($nodes as $node) {
    // do something awesome
  }
}


This will load all published nodes of type "page". You periodically need to adjust this to

$query = new EntityFieldQuery();

$query-&gt;entityCondition('entity_type', 'node')
  -&gt;entityCondition('bundle', 'page')
  -&gt;propertyCondition('status', 1);

$result = $query-&gt;execute();

if (!empty($result['node'])) {
  $nids = array_keys($result['node']);

 foreach ($nids as $nid) {
    $node = node_load($nid, NULL, TRUE);
    // do something awesome
  }
}


to avoid loading too much at once, which can cause memory issues.