need help with images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alidad
Forum Commoner
Posts: 29
Joined: Thu Mar 29, 2007 12:42 pm

need help with images

Post by Alidad »

Hi, this is relate to switch images, let say that i have two php files, and each files has one images called (red-images.png and yellow-images.png).

I'm trying to create switch program in php using two buttons of (red and yellow) buttons, and any time i click on that of those two buttons it will change images.

I'm using included statments

Code: Select all

(<?php include(); ?>)
to put

Code: Select all

<?php include('yellow.php'); ?>
or

Code: Select all

<?php include('red.php'); ?>.
my question is that how do i can write that php code to allow me to develop switch images button between red.php or yellow.php in index.php page using two of those buttons using

Code: Select all

<?php include(); ?>!
please help thanks.

AM
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: need help with images

Post by Jonah Bron »

You'll want to use a $_GET variable. The button will link to the same page, with something like "?color=red" appended to it. Then, when the page is loaded, you will check for a $_GET['color'] variable, and include the appropriate file. It would look something like this:

Code: Select all

if (isset($_GET['color'])){
    switch ($_GET['color']){
        case 'red':
            include('red.php');
            break;
        case 'yellow':
            include('yellow.php');
            break;
        default:
            include('default_color.php');
    }
}else{
    include('default_color.php');
}
Instead of 'default_color.php', you use whichever color you want to default to.

BTW, if you have code related questions (like this one), please post them in the PHP - Code form.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: need help with images

Post by pickle »

Moved.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply