2017-07-14 57 views
0

所以我有一個查詢正在運行,並且我在while循環中得到了結果。在while循環中,我想通過使用變量將$ image設置爲需要在html頁面上顯示的圖像的變量。我無法獲取在html上顯示的圖像。如何在PHP中將圖像設置爲變量並使用該變量以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;"> 

回答

1

只要改變$image = "<img src='images/image1.png'>";$image = "images/image1.png"; 然後執行:

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

或在您的情況

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

非常感謝你的工作 –

+0

不客氣:)我很高興它幫助你 –