需求:查出一个表的所有信息 让这个表的所有记录在一个表格的一行三列中 显示(通过读数据库来显示)
代码应该怎么写呢??
<table width="100%" border="1" cellpadding="0" cellspacing="0" align="center" >
<tr><td width="100%" align="center" colspan="3"><img src="images/index_yangzhi.jpg" border="0" /></td></tr>
<tr><td width="100%"> </td></tr>
<tr>
<?php
include_once("conn.php");
$sql="select * from yangzhi";
$rs=mysql_query($sql,$conn);
$num=mysql_num_rows($rs);
if($num%3==0){
$lienum=$num/3;
}else{
$lienum=$num/3+1;
}
$ii=1;
while($row=mysql_fetch_array($rs)){
if($ii%$lienum!=0){
echo("<td width='33%' align='center'>");
}
$ii++;
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="100%"><a href="js_detail.php?id=<?php echo $row[0];?>" style="text-decoration:none;"><?php echo $row[1];?></a></td></tr>
</table>
<?php
if($ii%$lienum==0){
echo("</td>");
}
}
?>
</tr>
</table>这样写 结果显示的不是1行 3列 乱套了 请高手点播一下
代码应该怎么写呢??
<table width="100%" border="1" cellpadding="0" cellspacing="0" align="center" >
<tr><td width="100%" align="center" colspan="3"><img src="images/index_yangzhi.jpg" border="0" /></td></tr>
<tr><td width="100%"> </td></tr>
<tr>
<?php
include_once("conn.php");
$sql="select * from yangzhi";
$rs=mysql_query($sql,$conn);
$num=mysql_num_rows($rs);
if($num%3==0){
$lienum=$num/3;
}else{
$lienum=$num/3+1;
}
$ii=1;
while($row=mysql_fetch_array($rs)){
if($ii%$lienum!=0){
echo("<td width='33%' align='center'>");
}
$ii++;
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="100%"><a href="js_detail.php?id=<?php echo $row[0];?>" style="text-decoration:none;"><?php echo $row[1];?></a></td></tr>
</table>
<?php
if($ii%$lienum==0){
echo("</td>");
}
}
?>
</tr>
</table>这样写 结果显示的不是1行 3列 乱套了 请高手点播一下
<?php
include_once("conn.php");
$sql="select * from yangzhi";
$rs=mysql_query($sql,$conn);
$i=0;
?>
<table>
<tr>
while($row = mysql_fetch_array($rs))
{
$i++;
echo "<td>$row[0]</td><td>$row[1]</td>";
if($i%3==0)
{
echo '</tr><tr>';
}
}
</tr>
</table>