Home  >  Article  >  Backend Development  >  Implementation code of PHP output table (revised version)_PHP tutorial

Implementation code of PHP output table (revised version)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:32:36925browse

Many codes on the Internet are wrong, and Script House has specially corrected them.

Copy code The code is as follows:



Two rows and five columns, a total of 10 data



< tr>
$num = 5; //Currently displays the number of columns in each row
$k = 1; //Initialization
while($k<=10)
{
if($k % $num == 0){
if($k==10){
echo '< /tr>'."rn";
}else{
echo ''."rn";
}

}
else {
echo ''."rn";
}

$k+=1; //Add
}
?>
'.$k.''.$k.'
'.$k.'




The following is read from the database:
Copy the code The code is as follows:

$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.= " ";
}
$str.= " ".$result[ "title "]. " ";
if(($i +1)%$num==0) {
$str.= " ";
}
}
?>

echo $str;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322763.htmlTechArticleMany codes on the Internet are wrong, and Script House has specially corrected them. Copy the code. The code is as follows: html head title, two rows and 5 columns, a total of 10 data/title /head body table border="1" width=8...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn