October 2002
Intermediate to advanced
368 pages
7h 12m
English
While loops are another useful construct to loop through data. While loops continue to loop until the expression in the while loop evaluates to false. A common use of the while loop is to return the rows in an array from a result set. The while loop continues to execute until all of the rows have been returned from the result set:
while($row = mysql_fetch_array($result)) {
// do something with the resulting row
}
You can also use the continue command to skip over the current iteration of the loop, then continue. For example:
while($row = mysql_fetch_array($result)) {
if($row['name'] ! = "Jet")) {
continue;
} else {
// do something with the row
}
Read now
Unlock full access