日期:2014-05-17  浏览次数:20589 次

一个控制图片按每行多少个输出的问题向大家求助!谢谢
我从数据库查询出很多的图片,我现在想控制每行只显示4张图片,图片底下显示出图片名字等等,但是我下面的代码总是不能正常工作.(如果不显示名字的话我已经知道怎么做了,因为要在图片底下显示文字,所以加了一个TR,图片就不能控制了.)

[code]

<!--     *************     Show   photo***************************   -->
<?php  
while   ($photoRows=mysql_fetch_array($result2)){
$i=$i+1;
?>
<table   width= "148 "   border= "0 "   >
<tr>
<td   width= "140 "   align= "left "   bgcolor= "#F0F0F0 ">
<TABLE   width=131   height=123   border=3   cellPadding=0   cellSpacing=1   >
<TR>
<TD   width= "107 "   height=74   align=middle   bgcolor= "#FFFFFF "> <div   align= "center ">   <a   href= "user.php?userid= <?php   echo   $photoRows[ "id "];?> &name= <?php   echo   $photoRows[ "user_name "];?> ">   <img   src=uploadfile/ <?php   echo   $photoRows[ "photo_name "];?>   border= "0 "   >   </a>   </div> </TD>
<TD   width= "16 "   rowspan= "2 "   align=middle   bgcolor= "#F0F0F0 "> &nbsp; </TD>
</TR>
<TR>
<TD   height= "31 "   bgcolor= "#DFDFDF "   align= "center ">
&nbsp; <FONT   style= "FONT-SIZE:   14px "   color= "#006699 "> <?php   echo   $photoRows[ "first_name "];?> </FONT> <br>
&nbsp; <?php   echo   "xxx ";?> <br>
&nbsp; <?php   echo   "xxx ";?>
</TD>
</TR>
<TR>
<TD   height= "14 "   bgcolor= "#F0F0F0 "   align= "center "> &nbsp; </TD>
<TD   align=middle   bgcolor= "#F0F0F0 "> &nbsp; </TD>
</TR>
</TABLE>
</td>  
<?php  
if($i%3==0   &&$i> =3)
{   echo   " <td> </tr> <TABLE   width=131   height=126   border=0> <tr> <td> &nbsp </td> </tr> <tr> <td> </td> </tr> </table> ";
echo   " </tr> <tr> </td> ";
?>  
<?php   }   }?>
[/code]

------解决方案--------------------
原理:循环单元格,在单元格中前导一个一列两行的表格即可,示例代码:
<table width= "100% " border= "0 " cellspacing= "0 " cellpadding= "0 ">
<tr>
<?php
....
$i=0;
while(){
if($i%3==0&&$i!=0){

}
?>
<td align= 'center '>
<table width= '100% ' border= '0 ' cellspacing= '0 ' cellpadding= '0 '>
<tr>
<td height= '160 ' align= 'center '>
图片
</td>
</tr>
<tr>
<td height= '28 ' align= 'center '>
标题
</td>
</tr>
</table>
</td>
<?php
$i++;
}
...
?>
</tr>
</table>
------解决方案--------------------
以前的例子
<?ph