ayachuca Posted November 3, 2009 Share Posted November 3, 2009 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 More sharing options...
JonnoTheDev Posted November 3, 2009 Share Posted November 3, 2009 <?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."\" />"; ?> Link to comment https://forums.phpfreaks.com/topic/180097-quesion-about-isset_getimage/#findComment-950089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.