php-Output a table

Source: Internet
Author: User

Output a table

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>23ptable</title>
<body>
<?php

Echo ' <table border= ' 1 "width=" align= "center" > ";
Echo ' <caption> uses a while loop output table </caption> ';
$i = 0;
while ($i <100) {


if ($i%10==0) {
echo "<tr>";} #此处, $i%10=0, exactly conditional statement set, output <tr>
echo "<td>". $i. " </td> ";
$i + +; #此处, $i is still 0.
if ($i%10==0) {
echo "</tr>";} /* here, $i is still 0, $i%10=0 set up, but the program out "}" is 1, if the $i + + is placed behind the IF,<tr></ The tr> is just a swap line, and the back loop will be in line * /  

}
echo "</table>";
?>
</body>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also achieve interlaced color change

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>23ptable</title>
<body>
<?php
Echo ' <table border= ' 1 "width=" align= "center" > ";
Echo ' <caption> uses a while loop output table </caption> ';
$i = 0;
while ($i <100) {
if ($i%10==0) {
      if ($i%20==0) {$bg = "#fff999";}    else{$BG = "#333fff";} effects such as
echo "<tr bgcolor= $bg >";}
echo "<td>". $i. " </td> ";
$i + +;
if ($i%10==0) {
echo "</tr>";}

}
echo "</table>";
?>
</body>

php-output a table

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.