Setting query offset
Not totally sure I understand everything going on in your example code, but I believe it could be a simplified a little:

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'affiliates';
$criteria-&gt;limit = null;

$rowCount = $criteria-&gt;total();
$batchSize = 100;
$numBatches = ceil($rowCount / $batchSize);

$criteria-&gt;limit = $batchSize;

for ($i = 0; $i &lt; $numBatches; ++$i) {
    $criteria-&gt;offset = $batchSize * $i;
    $affiliates = $criteria-&gt;find();
    foreach ($affiliates as $affiliate) {
        //process
    }
}


Tested, and works.