一个控制图片按每行多少个输出的问题向大家求助!谢谢
我从数据库查询出很多的图片,我现在想控制每行只显示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 "> </TD>
</TR>
<TR>
<TD height= "31 " bgcolor= "#DFDFDF " align= "center ">
<FONT style= "FONT-SIZE: 14px " color= "#006699 "> <?php echo $photoRows[ "first_name "];?> </FONT> <br>
<?php echo "xxx ";?> <br>
<?php echo "xxx ";?>
</TD>
</TR>
<TR>
<TD height= "14 " bgcolor= "#F0F0F0 " align= "center "> </TD>
<TD align=middle bgcolor= "#F0F0F0 "> </TD>
</TR>
</TABLE>
</td>
<?php
if($i%3==0 &&$i> =3)
{ echo " <td> </tr> <TABLE width=131 height=126 border=0> <tr> <td>   </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>
[解决办法]
以前的例子
<?php
$product_sql= "select * from product order by pub_time desc limit 4 ";
$product_query=mysql_query($product_sql);
$i=1;
while($product_result=mysql_fetch_array($product_query)){
?>
<td>
<table width= "100% " border= "0 " align= "left " cellpadding= "0 " cellspacing= "0 ">
<tr align= "center ">
<td height= "125 ">
<img src= " <?php echo $product_result[ "product_picture "]?> " width= "173 " height= "107 " border= "0 ">
</td>
</tr>
<tr align= "center ">
<td height= "35 ">
<?php echo $product_result[ "product_name "]?>
</td>
</tr>
</table>
</td>
<?php if($i%2== '0 '){echo " </tr> <tr> ";}$i++;?>
<?php }?>
[解决办法]
在php_in_china() 的代码里边上一句试试
<?php
....
$i=0;
while(){
if($i%3==0&&$i!=0){
echo " <tr> ";//加这句试试
}
?>
[解决办法]
用div + css就不用这么麻烦了 直接循环css控制换行,没那么多冗余代码
表格的话就会有多余的东西
需要换行的地方就 【插入】最后的这个 " </tr> <tr> "
【循环体】是 " <td> </td> "
<table>
<tr>
<td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr>
<td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr>
<td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr>
</tr>
</table>