php - Break While and Foreach Loop -
i have following code below, question is, want break out of while loop if user enters "n" , continue next foreach interation. please see comment within.
foreach($nodeid $nid){ $query= $dbh->query("select * nodes node_id = '$nid' , new = 1")or die(mysql_error()); if($query->rowcount() > 0) { while (1) { fputs(stdout, "\n"."***new node*** : $nid \n want add ? [y,n]: "); $response = strtolower(trim(fgets(stdin))); if( $response == 'y' ) { #do break , go next foreach. } elseif( $response == 'n' ) { #go next foreach $nid } else { echo "\n", "i don't understand option, let's try again", "\n"; continue; } } } }
you can:
continue 2;
in case. continue next run of outer foreach loop.
however, @tularis told in comments, simple break
have same effect here because no code following while
loop. (and might easier read)
about query. looks better here issue 1 database query ids, using in
statement:
$ids = impldode(',', $nodeids); // assuming ids integers $query= $dbh->query("select * nodes node_id in $ids , new = 1")
Comments
Post a Comment