Intereting Over Results

hi

I’ve got method:


protected function findUsersBatch($companyId,$page=1)

        {

                $criteria=new CDbCriteria();

                $criteria->compare('company_id',$companyId);

                $criteria->compare('active',0);

                $criteria->addCondition('import_time IS NOT NULL');

                $criteria->addCondition('invite_time IS NULL');

                $criteria->limit=self::BATCH_SIZE;

                $criteria->offset=($page-1)*self::BATCH_SIZE;

                return User::model()->findAll($criteria);

        }

and loop which iterates over it


$page=1;

while($data=$this->findUsersBatch($companyId,$page))

{

      foreach($data as $item)

      {

         ...do stuff

      }

      $page++;

}

batch size is 100

for given comapny I’v got ex. 1890 records

this code does 1000 recordes and stops

am’I missig smth here?


$criteria->limit=self::BATCH_SIZE;

:angry:

if your cirtieria->limit is 100 so it wil fetch only first 100 records

your $page is 1 so at every call to


$this->findUsersBatch($companyId,$page)

critieria offset is 0

no - $page is incremented


while($data=$this->findUsersBatch($companyId,$page))

{

      foreach($data as $item)

      {

         ...do stuff

      }


      $page++; <!----------- increment $page by one


}

it’s working witch first 10 “pages” (so it is iterating over fisrst 1000 records)

after it stopas (as findUsersBatch do not return recorsds)

i try this…and it returns even >1200 records…


public function findUsersBatch($page=1){

            	$criteria=new CDbCriteria();

            	$criteria->limit=100;

            	$criteria->offset=($page-1)*100;

            	return Contact::model()->findAll($criteria);

    	}




$page=1;


while($data=$this->findUsersBatch($page))

{

  	foreach($data as $item)

  	{

 		echo $item->id."<br>";

  	}

  	$page++;

}

which view you have used…CGridVIew or CListView ?

non of them, i use it in command to send emails (this is done in foreach on batch)

I’have also tried other version: i’ve made method countUsersToInvite() and chaged while loop





while($this->countUsersToInvite($companyId)) {

 $data=$this->findUsersBatch($page);

 foreach .....

 $page++;

}




and debug it, with each iteration count showed less records but after 1000 it stoped and $page stated to incerement to infinite