PHP output table implementation code of modified version

  • 2020-03-31 21:23:13
  • OfStack

A lot of the code on the Internet is wrong, this site has been fixed.

<html> 
<head> 
<title> Two lines 5 Column a total 10 A data </title> 
</head> 
<body> 
<table border="1" width=80%> 
<tr> 
<?php 
$num = 5; //The current number of columns per row is displayed
$k = 1; //Initialize the
while($k<=10) 
{ 
if($k % $num == 0){ 
if($k==10){ 
echo '<td>'.$k.'</td></tr>'."rn"; 
}else{ 
echo '<td>'.$k.'</td></tr><tr>'."rn"; 
} 

} 
else { 
echo '<td>'.$k.'</td>'."rn"; 
} 

$k+=1; //Since the add
} 
?> 
</table> 
</body> 
</html>

The following is read from the database:
 
<?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> 

Related articles: