0

我已经正确显示了此循环的第一轮。我想要的是 5 行 8 列。我得到的是第一组正确显示,第二组显示为 10 列。

我哪里错了?

echo '<table align="center" width="70%"><tr>'; 
$count = 0; 
$rowCount = 0;
while ( $row = mysql_fetch_array($result)) 
{ 
  $count++;    
  echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "' width='120' h     eight='160'/></a></td>"; 

if ($count % 8 === 0) 
{ 

    echo '</tr>';
$rowCount++;

if($rowCount % 8 === 0)
 {
    echo '</tr></table><br><br>Adds here<br><br><tablealign="center" width="70%"><tr>';
 }else{
    echo '<tr>';
 }
  } 
}     
echo ' </tr></table>'; 
4

1 回答 1

1

你试图让它变得有点太复杂了。

将列数与行数的功能分开:

<?php

echo '<table align="center" width="70%"><tr>'; 
$count = 0; 
$rowCount = 0;
while($row = mysql_fetch_array($result)) 
{ 
    $count++;
    echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "' width='120' h     eight='160'/></a></td>"; 
    if($count%8===0)
    {
        $rowCount++;
        echo '</tr>';

        if($rowCount%5===0)
        {
            echo '</table><br/><br/>Adds Here<br/><br/><table align="center" width="70%"><tr>';
            $rowCount = 0;
        }
    }
}
echo ' </tr></table>'; 
于 2012-08-31T14:02:52.347 回答