Do ... while statement will always execute the block of code once, then check the condition and repeat the loop while the condition is true.
Grammar
Todo
{
code to is executed;
}
while (condition);
For example
The following example defines a loop, which begins with i = 1. Then it will add 1 to me and write some output. Then, the condition is checked, the loop will continue to run like I just less than or equal to 5:
<body>
<?php
$i = 1;
Todo
{
$i + +;
echo "The number is". $i. "<br/>";
}
while ($i <=5);
?>
</body>
<?php
/* Example 1 * *
$i = 1;
while ($i <= 10) {
echo $i + +; /* The printed value would be
$i before the increment
(post-increment) * *
}
/* Example 2 * *
$i = 1;
while ($i <= 10):
echo $i;
$i + +;
Endwhile;
?>
<?php
$q 1 = ' Some query on a set of tables ';
$q 2 = ' Similar query on a another set of tables ';
if ($r 1=mysql_query ($q 1)) && ($r 2=mysql_query ($q 2)) {
while (($row =mysql_fetch_assoc ($r 1)) | | ($row =mysql_fetch_assoc ($r 2))) {
/* Do something with $row coming from $r 1 and $r 2 */
}
}
?>
<select name= "Whatever" >
<?php
while ($data = Mysql_fetch_assoc ($requeteID))
{
$menu. = ' <option value= '. $data [' id ']. ' ";
$menu. = ($data [' id '] = = $_get[' id ']? ' selected> ': ' > ');
$menu. = $data [' name ']. ' </option> ';
}
Echo $menu;
?>
</select>