Search code examples
phppropel

Propel: how do i retrieve all elements from database by one in a loop?


i try to do as follows:

$q = PhotographerQuery::create();
$photographer = $q->limit(1)->find();

while ($photographer) {
    $id = $photographer->getId();
    echo "$id {$photographer->getName()}\n";

    // do something - no idea what ... limit() supports only one parameter to
    // specify quontity of elements to be fetched
    $photographer = $q->limit(1)->somethingElse()->find();
}

How do I modify it to make this script up and running ?


Solution

  • You need to use offset but I honestly doubt that you really want it that way. For such use cases we have on-Demand-hydration: http://propelorm.org/documentation/03-basic-crud.html#collections-and-on-demand-hydration