为什么我的代码输出每个图像8次


Why does my code output each image 8 times?

我已经修复了之前的问题,但是现在循环为每个循环生成8个或更多的图像。在一个图库中,我有一个单独的图像,但是它被重复了八次,不是十次,也不是三次,这八次循环是怎么回事?

while($row = mysql_fetch_array($result)){   
    $AID = $row['AID'];
    $ThumbFilePath = $row['ThumbFilePath'];
    $Title = $row['Title'];
    $DisplayOrder = $row['DisplayOrder'];
    foreach($row as $cell)
    {
        echo "<div id='clear'></div>";
        echo "<div id='thumb_container'>";
        echo "<a href='gallery_detail.php?AID=$AID'><img src='http://markdinwiddie.com/PHP2012/$ThumbFilePath' title='Enlarge' alt='Enlarge' border='0'></a>";
        echo "<div id='name_spacer'></div>";
        echo "<div id='thumbdesc'>";
        echo "$Title";
        echo "</div>";
        echo "</div>";
    }                           
}

你有一个嵌套的循环

while($row = mysql_fetch_arry($result)){ //once for each row in the database
  foreach($row as $cell){ //once for each field in the table
  ...
  }
}

我猜你的表有8个字段。删除foreach{}

$result中选择的8列所以$row是一个包含8个元素的数组。

foreach($row as $cell)

foreach循环8次