在 PHP 中使用 while 循环创建图像表,最后一个条目回显到错误的位置


creating image tables with while loop in php and last entry echos to wrong location

我正在使用一个while循环将图像和标题回显到网页上。

我的问题是,当显示在页面上时,正在回显的最后一个图像(无论是图像编号 2 还是 6)都放置在页脚下方: 图像示例

无论出于何种原因,div"页脚"被添加到内容div的中间,我不知道为什么。为什么它会移动到它不属于的div 中,特别是在倒数第二个项目列表之后?

提前非常感谢!圈:

$query = ("SELECT * FROM photos");
$result = mysql_query($query);
$num = mysql_numrows($result);
$i=0;
while ($i<$num) {
    $name = mysql_result($result, $i, 'Name');
    $price = mysql_result($result, $i, 'Price');
    $price = '$'.$price;
    $description = mysql_result($result, $i, 'Description');
    $location = mysql_result($result, $i, 'Location');
    $id = mysql_result($result, $i, 'id');
    $status = mysql_result($result, $i, 'Status');
    echo "<table class='item'>
            <tr class='name'>
                <td><h2>" . $name . "</h2><h4>" . $type = ($status == "SOLD" ? $status : $price) . "</h4></td>
            </tr> 
            <tr class='imagelocation'>  
                <td><img src='" . $location . "' class='image'></td>
                <td class='itemdescription'>" . $description . " " . $price . "</td>
            </tr>
            ";
            $i++;
    }
?>
    </div>
</div>
<div id="footer">
<h5>For additional information, please <a href="contact.html">contact me</a>. <br />&nbsp;<br   />Copyright &copy; </h5>
</div>
<!-- end #footer -->
</body>

输出的 HTML:

<div class="item_list"> 
<table class="item">
            <tbody><tr class="name">
                <td><h2>Curtis</h2><h4>$8291.23</h4></td>
            </tr> 
            <tr class="imagelocation">  
                <td><img src="images/HDR1.jpg" class="image"></td>
                <td class="itemdescription">Lorem</td>
            </tr>
            </tbody></table>**<div id="footer">
</div>**<table class="item">
            <tbody><tr class="name">
                <td><h2>Vienna wall clock</h2><h4>SOLD</h4></td>
            </tr> 
            <tr class="imagelocation">  
                <td><img src="images/image001.jpg" class="image"></td>
                <td class="itemdescription">      </td>
            </tr>
</tbody></table></div>
echo "<table class='item'>
            <tr class='name'>
                <td><h2>" . $name . "</h2><h4>" . $type = ($status == "SOLD" ? $status : $price) . "</h4></td>
            </tr> 
            <tr class='imagelocation'>  
                <td><img src='" . $location . "' class='image'></td>
                <td class='itemdescription'>" . $description . " " . $price . "</td>
            </tr></table>
            ";