petehallw petehallw - 1 year ago 62
PHP Question

PHP echo to display image HTML

I am trying to display an image on my webpage using a PHP script to determine which image is displayed.
The image link is as follows:

<a href="gallery.php?image=image01">......</a>

My PHP script is thus:

$result = $_GET['image'];
echo '<img src="images/gallery/'.$result.'.jpg">';

So what I am trying to achieve in terms of HTML is:

<img src="images/gallery/image01.jpg">

The result I am getting is '"; ?>' displayed on the page.
Any help would be much appreciated!

Answer Source

I would change the gallery.php to this:

<?php $result = $_GET['image']; ?>
<img src="images/gallery/<?php echo $result; ?>.jpg">

That would simply it a little bit. You should echo out the result to see what you are getting when the variable is passed to the gallery page.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download