Home > php教程 > php手册 > php输出表格的实现代码(修正版)

php输出表格的实现代码(修正版)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:12:29
Original
1474 people have browsed it

网上的代码很多都是错误的,脚本之家特修正了下。

复制代码 代码如下:




二行5列一共10个数据




$num = 5; //当前每一行显示列数
$k = 1; //初始化
while($k{
if($k % $num == 0){
if($k==10){
echo ''."\r\n";
}else{
echo ''."\r\n";
}

}
else {
echo ''."\r\n";
}

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




下面是从数据库读取的:

复制代码 代码如下:


$sql = "select * from table ";
$query = mysql_query($sql);
$num = mysql_num_rows($query);
for($i=0;$i $result = mysql_fetch_array($query);
if($i%3==0){
$str.= "

";
}
$str.= " ".$result[ "title "]. " ";
if(($i+1)%$num==0) {
$str.= " ";
}
}
?>


echo $str;
?>

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template