比如我想在首页显示12个产品,分为3行显示,每行显示4个。可是效果显示的12个产品多到一行去了,请帮忙看看啊<?php
$sql="select id,pic,title from product where pic<>'' order by id desc limit 0,12";
$result=mysql_query($sql);
if(!$num=mysql_num_rows($result))
{
echo( "暂无产品数据!");
}
else
?>
<Br>
<table width="140" height="135" cellspacing="0" cellpadding="15">
<tr>
<?php
{
while($rs=mysql_fetch_array($result))
{
?>
<td><div align="center"><a href="product.php?id=<?=$rs["id"]?>" title="<?=$rs["title"]?>" ><img src="<?=$rs["pic"]?>" alt="<?=$rs["title"]?>" width="140" height="135" border="0" /></a><Br><Br>
<a href="product.php?id=<?=$rs["id"]?>" title="<?=$rs["title"]?>">
<?=msubstr($rs["title"],0,16)?>
</a> </div></td>
<?php
}
}
?>
$sql="select id,pic,title from product where pic<>'' order by id desc limit 0,12";
$result=mysql_query($sql);
if(!$num=mysql_num_rows($result))
{
echo( "暂无产品数据!");
}
else
?>
<Br>
<table width="140" height="135" cellspacing="0" cellpadding="15">
<tr>
<?php
{
while($rs=mysql_fetch_array($result))
{
?>
<td><div align="center"><a href="product.php?id=<?=$rs["id"]?>" title="<?=$rs["title"]?>" ><img src="<?=$rs["pic"]?>" alt="<?=$rs["title"]?>" width="140" height="135" border="0" /></a><Br><Br>
<a href="product.php?id=<?=$rs["id"]?>" title="<?=$rs["title"]?>">
<?=msubstr($rs["title"],0,16)?>
</a> </div></td>
<?php
}
}
?>
$sql="select id,pic,title from product where pic<>'' order by id desc limit 0,12";
$result=mysql_query($sql);
if(!$num=mysql_num_rows($result))
{
echo( "暂无产品数据!");
}
else
?>
<Br>
<table width="140" height="135" cellspacing="0" cellpadding="15">
<tr>
<?php
{
while($rs=mysql_fetch_array($result))
{
?>
<tr><td><div align="center"><a href="product.php?id=<?=$rs["id"]?>" title="<?=$rs["title"]?>" ><img src="<?=$rs["pic"]?>" alt="<?=$rs["title"]?>" width="140" height="135" border="0" /></a><Br><Br>
<a href="product.php?id=<?=$rs["id"]?>" title="<?=$rs["title"]?>">
<?=msubstr($rs["title"],0,16)?>
</a> </div></td></tr>
<?php
}
}
?>
<tr>才是列,<td>只是行
$sql="select id,pic,title from product where pic<>'' order by id desc limit 0,12";
$result=mysql_query($sql);
if(!$num=mysql_num_rows($result))
{
echo( "暂无产品数据!");
}
else
?>
<Br>
<table width="140" height="135" cellspacing="0" cellpadding="15">
<tr>
<?php
{
$i=0;
while($rs=mysql_fetch_array($result))
{
if ($i%4==0)
echo "<tr>";
$i++;
?>
<td><div align="center"><a href="product.php?id=<?=$rs["id"]?>" title="<?=$rs["title"]?>" ><img src="<?=$rs["pic"]?>" alt="<?=$rs["title"]?>" width="140" height="135" border="0" /></a><Br><Br>
<a href="product.php?id=<?=$rs["id"]?>" title="<?=$rs["title"]?>">
<?=msubstr($rs["title"],0,16)?>
</a> </div></td>
<?php
}
}
?>