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>