Question

Given this code:

while($thisrow = mysqli_fetch_array($thisresult)){
    if($thisrow['displaythis'] == 'yes'){
        echo $thisrow['name'];
    } else {
        continue;
    }
        $associatedquery = "select * from database where id = $thisrow['associated']";
        $result = mysqli_query($associatedquery);
        while($row = mysqli_fetch_array($result)){
            echo $row['name'];
        }
 }

If $thisrow['displaythis'] == no, is it going to 'continue' to process the associatedquery, or is it going to go back to the next value in the first while statement? If not, how can I jump back to the next value in the first while statement and skip the associatedquery? I know I can put the whole 'associatedquery' segment inside the if = 'yes' statement, but I don't want to do that.

Was it helpful?

Solution

Continue skips further processing of current iteration and goes to the next iteration.

OTHER TIPS

To answer your question, continue will go back to the loop statement and start over with the next value in the loop, it will not execute any of the lower half of your loop after the continue statement. If statements are not loops, but for, while, and switch statements are considered loops in php

So the answer to your question is YES

Here is a more in depth explanation

Q: Is it going to go back to the next value in the first while statement?

A: Yes, because continue will 'continue' checking for the expected value from the if condition in the loop and skip the execution of the rest of the code until you break the loop or it finishes.

Check some examples and usage at:

http://es1.php.net/continue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top