dounuogong0358 2017-01-13 11:39
浏览 64
已采纳

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

So i have the PHP code to call and display the product from mysql.. i have a problem with displaying the picture.. when a user add the item to database, (database as shown in picture) when the picture is uploaded, its store in a folder in localhost and on the database.. it will auto create a random number for the picture to store.. so how should i call the picture to be viewed? in line:

img/ is the folder in localhost.

DATABASE EXP:

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; ?>

</div>
  • 写回答

2条回答 默认 最新

  • drutcs7210 2017-01-13 11:44
    关注
        <?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条)

报告相同问题?

悬赏问题

  • ¥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数据包括密码,可以复制到另一手机上运行