0

So i have a query running and i get results in a while loop. 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. I am not able to get the image displayed on the html.

By the way the images are located in the folder.

PHP Code :

    if ($result->num_rows > 0) {

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

HTML Code:

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

1 Answer 1

1

Just change $image = "<img src='images/image1.png'>"; to $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;"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.