请指点一下这个循环语句如何让它执行数据5个后自动换行
}#jkdiv#jk{width:200px;}</style></head><body><tablewidth="200"border="0"cellpadding="...
}
#jk div #jk {
width: 200px;
}
</style>
</head><body>
<table width="200" border="0" cellpadding="0">
<tr>
<?php
while ($row_ji = mysql_fetch_assoc($ji)) {
?>
<td><table width="200" border="0" cellpadding="0">
<tr>
<td>姓名:<?php echo $row_ji['groupname']; ?></td>
</tr>
<tr>
<td>行业:<?php echo $row_ji['src']; ?></td>
</tr>
<tr>
<td>电话:<?php echo $row_ji['url']; ?></td>
</tr>
</table></td>
<?php
} ?>
</tr>
</table></body>
</html>
<?php
mysql_free_result($ji);mysql_free_result($Recordset1);
?> 展开
#jk div #jk {
width: 200px;
}
</style>
</head><body>
<table width="200" border="0" cellpadding="0">
<tr>
<?php
while ($row_ji = mysql_fetch_assoc($ji)) {
?>
<td><table width="200" border="0" cellpadding="0">
<tr>
<td>姓名:<?php echo $row_ji['groupname']; ?></td>
</tr>
<tr>
<td>行业:<?php echo $row_ji['src']; ?></td>
</tr>
<tr>
<td>电话:<?php echo $row_ji['url']; ?></td>
</tr>
</table></td>
<?php
} ?>
</tr>
</table></body>
</html>
<?php
mysql_free_result($ji);mysql_free_result($Recordset1);
?> 展开
1个回答
展开全部
下面的代码需要修改:
<?php
while ($row_ji = mysql_fetch_assoc($ji)) {
?>
<td><table width="200" border="0" cellpadding="0">
<tr>
<td>姓名:<?php echo $row_ji['groupname']; ?></td>
</tr>
<tr>
<td>行业:<?php echo $row_ji['src']; ?></td>
</tr>
<tr>
<td>电话:<?php echo $row_ji['url']; ?></td>
</tr>
</table></td>
<?php
} ?>
循环里面增加计数器,满5个就换行,代码如下:
<?php
$iii=0;//已经输出的个数
while ($row_ji = mysql_fetch_assoc($ji)) {
if ($iii=0) echo '<tr>';
echo <<<END
<td><table width="200" border="0" cellpadding="0">
<tr> <td>姓名:{$row_ji['groupname']}</td> </tr>
<tr> <td>行业:{$row_ji['src']}</td> </tr>
<tr> <td>电话:{$row_ji['url']}</td> </tr>
</table></td>
END;
if ($iii=0) echo '</tr>';
$iii++;
if ($iii>5) $iii=0;
}
?>
追问
第5行出现语言错误
追答
你是粘贴的吗,最好拷屏你的代码,5行没有错,4行和14行有错,=应该修改为==
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询