Jump to content

Quesion about - isset($_GET['image']) !


Recommended Posts

Hello,

 

I'm having one problem. Since I'm not PHP developer, I don't know how to solve it.

 

I'm having two pages.

 

Page1 have two images that are linked to:

 

...page2.php?image=1

...page2.php?image=2

 

On click on one of those links, on Page2, I need to change one image with another.

So, for example, when I click on link "...page2.php?=image1", it should open me Page2 with new image loaded in some place.

Same, when I click on "...page2.php?=image2", it opens me another image on Page2.

 

Since I need to update website and there was code only for one image:

 

<img src="pic/<?php echo isset($_GET['image']) ? 'promospace2.gif' : 'middle_highlights.gif';?>" height="740" width="450"/>

 

Can anyone help me and tell me how to make this code for 2 images/links?

I'm guessing that there should be an "if and then/else" loop, but I'm dumb enough, so anyone please ? :)

Link to comment
https://forums.phpfreaks.com/topic/180097-quesion-about-isset_getimage/
Share on other sites

<?php
// array of images
$images[1] = "promospace2.gif";
$images[2] = "anotherimage.gif";

if(is_numeric($_GET['image']) && array_key_exists($_GET['image'],$images)) {
$image = $images[$_GET['image']];
}
else {
// image does not exist
$image = "middle_highlights.gif";
}
// display image
print "<img src=\"pic/".$image."\" />";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.