【问题标题】:Retrieve and Display image from database not displaying image in proper format从数据库中检索和显示图像未以正确格式显示图像
【发布时间】:2013-10-27 10:17:45
【问题描述】:

我正在使用 woo-commerce 插件。我有自定义插件从前端添加产品,它工作正常,我已成功将产品添加到数据库中,现在我必须将该产品图像显示到 class="product -thumbn 作为我的产品下面是我的代码我不知道如何做到这一点。

<td class="product-thumbnail" >
            <?php
              global $wpdb;
           $result = $wpdb->get_results ( "SELECT * FROM user_templates  where id= '14' " );

             foreach ( $result as $print )  
           echo $print->BgImageName;

         echo '<img src="/user_templates/'.$print->BgImageName.'"/>';
                                       ?>
             </td>

我在这里得到一个波纹管输出我只得到图像名称而不是图像。

【问题讨论】:

  • 首先您是否只为图像名称执行 SQL 查询?如果是这样,请将 * 更改为只是 BgImageName。您还可以向我们展示 html 输出吗?从您的代码中,我了解到您希望输出代码为“”,但仅通过查看图片很难知道发生了什么。

标签: php wordpress woocommerce


【解决方案1】:

得到了正确的答案...

<td class="product-thumbnail" >
                <?php
    global $wpdb;
     $result = $wpdb->get_results ( "SELECT * FROM user_templates  where id= ".$_SESSION['user_te']);
    foreach ( $result as $print )  
    $img_post=$print->BgImageName;
     // echo '<img src="src="../user_templates/'//.$print->BgImageName.'"/>';
        ?>                                                   
     <image height="100"src="../user_templates/<?php echo $img_post;?>" />

      </td>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    相关资源
    最近更新 更多