【问题标题】:How to Set Image as a Variable in Php and display the image in HTML using that variable如何在 PHP 中将图像设置为变量并使用该变量在 HTML 中显示图像
【发布时间】:2017-07-14 19:40:24
【问题描述】:

所以我有一个查询正在运行,我在一个 while 循环中得到结果。在 while 循环中,我想通过使用变量将 $image 设置为需要在 html 页面上显示的图像的变量。我无法在 html 上显示图像。

顺便说一下,图像位于文件夹中。

PHP 代码:

    if ($result->num_rows > 0) {

while($row = $result->fetch_assoc()) {
          $image = "<img src='images/image1.png'>";
    }
}

HTML 代码:

<?php include 'File.php';?>
 <img src="<?php echo $image; ?>" alt="Mountain View" style="width:304px;height:228px;">

【问题讨论】:

    标签: php html


    【解决方案1】:

    只需将$image = "&lt;img src='images/image1.png'&gt;"; 更改为$image = "images/image1.png"; 然后做:

    echo '<img src="' . $image . '"/>';
    

    或者在你的情况下

    <img src="<?php echo $image; ?>" alt="Mountain View" style="width:304px;height:228px;"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      • 1970-01-01
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      相关资源
      最近更新 更多