cdbdatareader foreach

hello, i’m triyng to compare somedates in datareader foreach .


$rows = Yii::app()->db->createCommand($myproc)->query();

$precos = Yii::app()->db->createCommand($myproc)->query();


foreach ($rows as $row) {

            $start = $row['inicio'];

            $dtEnd = $row['fim'];


            $dtLoop = date('Y-m-j', strtotime("+1 day", strtotime($start)));


            $dtEnd = date('Y-m-j', strtotime("-1 day", strtotime($dtEnd)));





    While ($dtLoop <= $dtEnd) {

             

              foreach ($precos as $preco) {


                    $start2 = $preco['inicio'];

                    $dtEnd2 = $preco['fim'];

                    $dtLoop2 = $start2;

                   

                     While ($dtLoop2 <= $dtEnd2) {


                      if ($start==$dtEnd2){

                      $js = $js . ("[" . date("m", strtotime($start)) . ", " . date("d", strtotime($start)) . ", " . date("y", strtotime($start)) . "]");


                      $js = $js . (",");


                      }


                      if ($start2==$dtEnd){

                      $js = $js . ("[" . date("m", strtotime($dtEnd)) . ", " . date("d", strtotime($dtEnd)) .

", " . date("y", strtotime($dtEnd)) . "]");


                      $js = $js . (",");


                      }


                      $dtLoop2 = date('Y-m-j', strtotime("+1 day", strtotime($dtLoop2)));




                      }

I can’t run the second foreach because error:“CDbDataReader cannot rewind. It is a forward-only reader.”

but it’s a diferent object. Do you have any ideas?

But second foreach is running in a while loop so it is obviously run more than once.

You can fetch all rows directly:


$precos = Yii::app()->db->createCommand($myproc)->queryAll();

or


$precos = Yii::app()->db->createCommand($myproc)->query()->readAll();

thanks for yourtime, i’m new to yii and php. Strange behaviour hapens with this code , only firts record is returned, can you help me. Thanks


foreach ($rows as $row) {

            $start = $row['inicio'];

            $dtEnd = $row['fim'];







            $dtLoop = date('Y-m-j', strtotime("+1 day", strtotime($row['inicio'])));


            $dtEnd = date('Y-m-j', strtotime("-1 day", strtotime($row['fim'])));





           While ($dtLoop <= $dtEnd) {

 

                $js = $js . ("[" . date("m", strtotime($dtLoop)) . ", " . date("d", strtotime($dtLoop)) . ", " . date("Y", strtotime($dtLoop)) . "]");


                $js = $js . (",");

                $dtLoop = date('Y-m-j', strtotime("+1 day", strtotime($dtLoop)));

                echo $dtLoop."----";

                echo $dtEnd;

            }

            

        }