所以我有PHP代码来调用和显示mysql的产品.. 我有一个显示图片的问题..当用户将图片上传到数据库时,(图片中显示数据库)上传图片时,它存储在localhost和数据库中的文件夹中..它会自动创建一个要存储的图片的随机数..那么我该如何调用要查看的图片?在线:
img /是localhost中的文件夹。
DATABASE EXP:
<?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();
?>
&#13;
<?php echo $dynamicList; ?>
&#13;
答案 0 :(得分:0)
<?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();
?>
答案 1 :(得分:0)
您确定,img/1.jpg
下有照片吗?您写道,图片中会有一个随机数,但正如我所看到的,您正在使用数据库主键标识符。