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
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"

Link to comment
Share on other sites

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. ;D Thanks, I'll try that and get back to ye.

Link to comment
Share on other sites

<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

Link to comment
Share on other sites

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.