gpt4 book ai didi

php - 如何在php中显示来自mysql的图像

转载 作者:行者123 更新时间:2023-11-29 19:33:55 28 4
gpt4 key购买 nike

所以我有 PHP 代码来调用并显示来自 mysql 的产品..我在显示图片时遇到问题..当用户将项目添加到数据库(如图所示的数据库)时,上传图片时,它存储在本地主机和数据库中的文件夹中..它将自动创建一个要存储的图片的随机数..那么我应该如何调用要查看的图片?行中:

img/是本地主机中的文件夹。

数据库经验:

enter image description here

<?php 
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "dbconnect.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM product ORDER BY proDate DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$proID = $row["proID"];
$proName = $row["proName"];
$proPrice = $row["proPrice"];
$proDate = strftime("%b %d, %Y", strtotime($row["proDate"]));
$dynamicList .= '

<div class="single-product">
<div class="product-f-image">
<img src="img/' . $proID . '.jpg" alt="">
<div class="product-hover">
<a href="#" class="add-to-cart-link"><i class="fa fa-shopping-cart"></i> Add to cart</a>
<a href="single-product.php?id=' . $proID . '" class="view-details-link"><i class="fa fa-link"></i> See details</a>
</div>
</div>

<h2>' . $proName . '</h2>

<div class="product-carousel-price">
<ins>$' . $proPrice . '</ins> <del>$425.00</del>
</div>
</div>
';

}
} else {
$dynamicList = "no new products";
}
mysql_close();
?>
<?php echo $dynamicList; ?>

最佳答案

    <?php 
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "dbconnect.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM product ORDER BY proDate DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$proID = $row["proID"];
$proImg = $row["proImg"];
$proName = $row["proName"];
$proPrice = $row["proPrice"];
$proDate = strftime("%b %d, %Y", strtotime($row["proDate"]));
$dynamicList .= '

<div class="single-product">
<div class="product-f-image">
<img src="img/' . $proImg . '" alt="">
<div class="product-hover">
<a href="#" class="add-to-cart-link"><i class="fa fa-shopping-cart"></i> Add to cart</a>
<a href="single-product.php?id=' . $proID . '" class="view-details-link"><i class="fa fa-link"></i> See details</a>
</div>
</div>

<h2>' . $proName . '</h2>

<div class="product-carousel-price">
<ins>$' . $proPrice . '</ins> <del>$425.00</del>
</div>
</div>
';

}
} else {
$dynamicList = "no new products";
}
mysql_close();
?>

关于php - 如何在php中显示来自mysql的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41633820/

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