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条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动