PHP Do While statement

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.