doulangtiao4508 2013-11-17 05:26
浏览 41
已采纳

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

I am using a while loop to echo images and titles to a webpage.

My problem is that the last image being echoed (whether it is image number 2 or 6) is placed below the footer when displayed on the page: Image example

For whatever reason the div "footer" is being added in the middle of the content div and I have no idea why. Why would it be moving into a div it doesn't belong in, and specifically right after the second to last item listing?

Thank you much in advance! Loop:

$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>

Outputted 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>
  • 写回答

1条回答 默认 最新

  • dousi4900 2013-11-17 05:39
    关注
    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>
                ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行