Jump to content

[SOLVED] Switch between Images PHP?


Cetanu

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/167503-solved-switch-between-images-php/
Share on other sites

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"

<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! :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.