简体   繁体   English

如何在Php中将图像设置为变量并使用该变量在HTML中显示图像

[英]How to Set Image as a Variable in Php and display the image in HTML using that variable

So i have a query running and i get results in a while loop. 所以我有一个查询正在运行,我在while循环中得到结果。 In the while loop I want to set $image as a variable for a image that is needed to be displayed on a html page, by using the variable. 在while循环中,我想通过使用变量将$ image设置为需要在html页面上显示的图像的变量。 I am not able to get the image displayed on the html. 我无法获取显示在html上的图像。

By the way the images are located in the folder. 顺便说一下,图像位于文件夹中。

PHP Code : PHP代码:

    if ($result->num_rows > 0) {

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

HTML Code: HTML代码:

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

Just change $image = "<img src='images/image1.png'>"; 只需更改$image = "<img src='images/image1.png'>"; to $image = "images/image1.png"; $image = "images/image1.png"; and then do: 然后执行:

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

or in your case 还是你的情况

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM