Cetanu Posted July 26, 2009 Share Posted July 26, 2009 I was wondering, is there a way (with PHP) that will make it possible for someone to load different images depending on what they click? I am using image maps for a tutorial and I thought, rather than have a million pages for each page of the tutorial, I could have PHP switch between images. So, if they're on Page 1 and click "Next" it won't take them to a new page, it will just load up a new image map that replaces the old one. Is that possible? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Vebut Posted July 26, 2009 Share Posted July 26, 2009 Sure it's possible: <?php if (!array_key_exists('page', $_GET)) $_GET['page'] = ''; switch ($_GET['page']) { case "page1": echo "Page 1 image"; break; case "page2": echo "Page 2 image"; break; default: echo "Default page image"; break; } ?> This script uses the $_GET global which is set by e.g href="page=page1" Quote Link to comment Share on other sites More sharing options...
Cetanu Posted July 26, 2009 Author Share Posted July 26, 2009 But how would I make a link do that? If I want it to switch whenever the link is clicked...would I need to name the link? >.><.< Nevermind I see it at the bottom. Thanks, I'll try that and get back to ye. Quote Link to comment Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 If you have many pages you will not want to use switch either but select the image file itself dynamically instead. Quote Link to comment Share on other sites More sharing options...
Cetanu Posted July 26, 2009 Author Share Posted July 26, 2009 <html> <head> <title>PHP Tutorial</title> <style type="text/css"> body{ background-color: #333; } a#img{ border: 0; } </style> </head> <body> <map name="begin"> <area shape="rect" coords="409,347,577,401" title="Begin" href="page=page1"> </map> <map name="p1"> <area shape="rect" coords="409,347,577,401" title="Begin" href="page=page2"> </map> <?php if (!array_key_exists('page', $_GET)) $_GET['page'] = ''; switch ($_GET['page']) { case "page1": echo "<p style=\"text-align: center; display: block; margin: 0 auto;\"><img src=\"P1.png\" usemap=\"#p1\" border=\"0\"/></p>"; break; case "page2": echo "P2.png"; break; default: echo "<p style=\"text-align: center; display: block; margin: 0 auto;\"><img src=\"Start.png\" usemap=\"#begin\" border=\"0\"/></p>"; break; } ?> </body> </html> That is my code and when I click the BEGIN link that takes me to Page 1 it tells me page 1 is non-existent. Please help! Quote Link to comment Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 You need to have a proper link in the href attribute. ?page=page1, not page=page1. Quote Link to comment Share on other sites More sharing options...
Vebut Posted July 26, 2009 Share Posted July 26, 2009 You need to have a proper link in the href attribute. ?page=page1, not page=page1. ahh, my misstake. Yes, a proper link in the href attribute is required. vineld's example link should work. Quote Link to comment Share on other sites More sharing options...
Cetanu Posted July 26, 2009 Author Share Posted July 26, 2009 HOLY CRAP. Thanks guys-- tremendous help!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.