Php output Table Implementation Code (revised version)

Source: Internet
Author: User

Many of the Code on the internet is incorrect.
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> 10 data records in five columns in two rows </title>
</Head>
<Body>
<Table border = "1" width = 80%>
<Tr>
<? Php
$ Num = 5; // The number of columns displayed in each row
$ K = 1; // Initialization
While ($ k <= 10)
{
If ($ k % $ num = 0 ){
If ($ k = 10 ){
Echo '<td>'. $ k. '</td> </tr>'. "\ r \ n ";
} Else {
Echo '<td>'. $ k. '</td> </tr> <tr>'. "\ r \ n ";
}

}
Else {
Echo '<td>'. $ k. '</td>'. "\ r \ n ";
}

$ K + = 1; // auto-Increment
}
?>
</Table>
</Body>
</Html>

The following is what is read from the database:
Copy codeThe Code is as follows:
<? Php
$ SQL = "select * from table ";
$ Query = mysql_query ($ SQL );
$ Num = mysql_num_rows ($ query );
For ($ I = 0; $ I <$ num; $ I ++ ){
$ Result = mysql_fetch_array ($ query );
If ($ I % 3 = 0 ){
$ Str. = "<tr style = 'word-break: break-all'> ";
}
$ Str. = "<td>". $ result ["title"]. "</td> ";
If ($ I + 1) % $ num = 0 ){
$ Str. = "</tr> ";
}
}
?>
<Table border = 0>
<?
Echo $ str;
?>
</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.