I have loop and using php break and continue methods but those are not working. Can you tell me how to use break and continue methods in yii? Here is my loop
if($this->enforceBookOwnerRadio == 1 ) {
; // Drop down to rest of processing
goto FinishedValidating; ---this is not working too
} elseif($this->enforceBookOwnerRadio == 3) {
continue; //Skip to the next Book
} elseif($this->enforceBookOwnerRadio == 4) {
$abortReason="User Chose: Abort Book not owned by this User";
break; //Break out of the for loop. Use the $$abortReason variable to display an information message.
} elseif ($this->enforceBookOwnerRadio == 2) {
$this->enforceBookOwner=0; // Don’t check owner for any more Books. Fall through to rest of processing.
} else { // If you get here then the program has a bug.
$programError="Program error, wrong user enforceBookOwner";
Would be nice if you can post your complete loop… and enclose the code with the code button <>… or use the code directives [ code] and [ /code] (without space), so the code is more readable
for ($book=$this->startRange;$book <= $this->endRange; $book++) {
$connection = Yii::app()->db;
$sql="SELECT id,User_id,Lab_id from BookRecords where tn='$book'";
$command=$connection->createCommand($sql);
$row = $command->queryRow();
$abortReason="";
$programError="";
if($row[User_id] != Yii::app()->user->id) {
if($this->enforceBookOwnerRadio == 1 ) {
; // Drop down to rest of processing
goto FinishedValidating; ---this is not working too
} elseif($this->enforceBookOwnerRadio == 3) {
continue; //Skip to the next Book
} elseif($this->enforceBookOwnerRadio == 4) {
$abortReason="User Chose: Abort Book not owned by this User";
break; //Break out of the for loop. Use the $$abortReason variable to display an information message.
} elseif ($this->enforceBookOwnerRadio == 2) {
$this->enforceBookOwner=0; // Don't check owner for any more Books. Fall through to rest of processing.
} else { // If you get here then the program has a bug.
$programError="Program error, wrong user enforceBookOwner";
break;
}
}
for ( $book=$this->startRange; $book <= $this->endRange; $book++ )
{
$connection = Yii::app()->db;
$sql="SELECT id,User_id,Lab_id from BookRecords where tn='$book'";
$command=$connection->createCommand($sql);
$row = $command->queryRow();
$abortReason="";
$programError="";
if( $row[User_id] != Yii::app()->user->id )
{
if($this->enforceBookOwnerRadio == 1 )
{
; // Drop down to rest of processing
goto 'FinishedValidating'; //---this is not working too
}
elseif($this->enforceBookOwnerRadio == 3)
{
continue; //Skip to the next Book
}
elseif($this->enforceBookOwnerRadio == 4)
{
$abortReason="User Chose: Abort Book not owned by this User";
break; //Break out of the for loop. Use the $$abortReason variable to display an information message.
}
elseif ($this->enforceBookOwnerRadio == 2)
{
$this->enforceBookOwner=0; // Don't check owner for any more Books. Fall through to rest of processing.
}
else
{ // If you get here then the program has a bug.
$programError="Program error, wrong user enforceBookOwner";
break;
}
}
// BEGIN inseting Reocrds into Table:
} //End For Loop
<?php echo CHtml::activeRadioButtonList($form,'enforceBookOwnerRadio ',array(1=>“Yes to All Books”,2=>“Yes for this Book”,3=>“No for this Book”,4=>“No to All Books”)); ?>
Can you explain me what you need to be done… what is the expected …
If that variable has always the same value… .than why are you using a loop… say for example that the value is 3… than you would just "continue" in a loop
suppose I want to enter these id 5713799980-9999, it will check if this user has own this id or not, then user will choose one of four option(<?php echo CHtml::activeRadioButtonList($form,'enforceBookOwnerRadio ',array(1=>“Yes to All Books”,2=>“Yes for this Book”,3=>“No for this Book”,4=>“No to All Books”)); ?>)
. if user check $this->enforceBookOwnerRadio ==1 then it will insert all records(5713799980-9999) to database, if user check $this->enforceBookOwnerRadio ==2, then it will insert only 5713799980 number, if $this->enforceBookOwnerRadio ==3 then Skip to the next number, and if $this->enforceBookOwnerRadio ==4 then back to original page.
I don’t think you are using goto properly. The goto’s target point should not be in quotations. Also, make sure that you are at least running PHP 5.3. The goto control structure does not work in earlier versions.
There are 2 separate lines of code for a goto statement to work. First is the goto operator followed by the target point:
goto FinishedValidating;
Second is the target point:
FinishedValidating:
The second part is where the code goes to when the goto operator is used. Where are you putting the target point? I don’t see it in the code you posted.
It should work. Goto works when I use it. There may be something else wrong with your code. Be sure and post any errors you receive. Other than that, I’m out of ideas.