gpt4 book ai didi

php - 使用php mysql动态显示图像

转载 作者:行者123 更新时间:2023-11-30 00:50:44 24 4
gpt4 key购买 nike

我正在尝试使用 mysql 检索这行硬编码图像,将其转换为动态代码。

<div class="item-block-1">
<span class="tag-sale"></span>
<div class="image-wrapper">
<div class="image">
<div class="overlay">
<div class="position">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis metus non erat tincidunt consectetur. Maecenas ac turpis id lorem.</p>
<a href="#" class="quickshop">Quick shop</a>
</div>
</div>
</div>
<a href="#"><img src="images/photos/photo-3.jpg" style="margin: -32.5px 0 0 0;" alt="" /></a>
</div>
</div>
<h2><a href="pandora-item.html">Polka dot light blue blouse</a></h2>
<p class="price">$13.99<s>$36.99</s></p>
</div>

我的动态代码如下,但它只允许我检索一张图像,而不是循环遍历代码..

<div class="item-block-1">
<div class="image-wrapper">
<div class="image">
<div class="overlay">
<div class="position">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis metus non erat tincidunt consectetur. Maecenas ac turpis id lorem.</p>
<a href="#" class="quickshop">Quick shop</a>
</div>
</div>
</div>
<?php

$result = mysql_query("SELECT * FROM my_image", $connection);


while($row = mysql_fetch_array($result))
{
echo "<div><img src=\"uploadedimages/".$row['name']."\" /></div>";
}
?>
</div>
</div>

有人可以纠正我吗?

最佳答案

试试这个代码

<?php
$result = mysql_query("SELECT * FROM my_image");
?>
<div class="item-block-1">
<div class="image-wrapper">
<div class="image">
<div class="overlay">
<div class="position">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis metus non erat tincidunt consectetur. Maecenas ac turpis id lorem.</p>
<a href="#" class="quickshop">Quick shop</a>
</div>
</div>
</div>
<?php
while($row = mysql_fetch_array($result))
{
?>
<div>
<img src="new/<?php echo $row['name']; ?>"/>
</div>
<?php
}
?>
</div>
</div>
</div>

关于php - 使用php mysql动态显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21003337/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com