可以定义一个变量,初始值为1。然后在循环的时候不要写在<tr></tr>之间,而是<tr></td>之间,然后循环后面把变量+1,最后判断是否等于4,如果是就echo一个</tr>.思想就是这样,相信你行的。

解决方案 »

  1.   

    <? $exec="select * from pic_img where sortid='$rssort->id' order by id desc";//求总的记录数
    $result=mysql_query($exec); $recountCount = mysql_num_rows($result);
    $totalPage = ceil($recountCount/40);
    $page = (isset($page) && $page>=0)? $page: 0;
    $isLast = ($page==($totalPage-1))? true: false;
    $hasNoPre = ($page==0)? true: false;
    $hasNoNext = ($page==$totalPage-1)? true: false;
    $isFirst = ($page==0)? true:false; $exec="select * from pic_img where sortid='$rssort->id' order by id desc limit ".($page*40).",40";//一页是40记录的
     
    $result=mysql_query($exec);
       $count=mysql_num_rows($result);
       $col=4;
    $row=floor($count/$col);
    $eol=$count%$col;
    if($eol>0)
    $row++;
    for($i=0; $i<$row; $i++)
    {
    echo "<tr>";
    for($j=0; $j<$col; $j++)
    {
    $rslist=mysql_fetch_object($result);
        if($rslist==false)
    echo "";
    else {
    ?>
    <TD>
    <TABLE cellSpacing=1 cellPadding=5 width=128 bgColor=#cecece border=0>
    <TBODY>
    <TR>
    <TD align=middle bgColor=#ffffff>
    <a href="view.php?pid=<? echo "$rslist->id"; ?>" target="_blank"><IMG src="<? echo "$siteurl$imgpath$rslist->imgsmall"; ?>" height=90 width=120 border=0></a><BR>
    <TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
    <TBODY>
    <TR>
    <TD align=middle height=42><? echo "$rslist->imgname"; ?></TD>
    </TR>
    </TBODY>
    </TABLE >
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </TD>
    <?
    } }
    echo "</tr>";
    }
     ?>
    <TR>
    <TD colspan="4">
    <TABLE cellSpacing=1 cellPadding=5 width=100% align="center" bgColor=#cecece border=0>
    <TBODY>
    <TR>
    <TD align=right bgColor=#ffffff>
    <?
      $str  = "共 $recountCount 条,当前 ".($page+1)."/$totalPage 页&nbsp;&nbsp;&nbsp;&nbsp;";
      $str .= $isFirst?   "首页&nbsp;"   : "<a href=\"sort.php?oid=$oid&page=0\">首页</a>&nbsp;";
      $str .= $hasNoPre?  "上页&nbsp;" : "<a href=\"sort.php?oid=$oid&page=".($page-1)."\">上页</a>&nbsp;";
      $str .= $hasNoNext? "下页&nbsp;" : "<a name=\"morelist\" href=\"sort.php?oid=$oid&page=".($page+1)."\">下页</a>&nbsp;";
      $str .= $isLast?    "尾页&nbsp;"   : "<a href=\"sort.php?oid=$oid&page=".($totalPage-1)."\">尾页</a>";
      echo $str;
    ?>