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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料