Page 1 of 1

need help with images

Posted: Thu Jan 14, 2010 4:26 pm
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

Re: need help with images

Posted: Fri Jan 15, 2010 11:20 am
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.

Re: need help with images

Posted: Fri Jan 15, 2010 11:29 am
by pickle
Moved.