Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-07-2008, 10:11 PM   PM User | #1
reach100
New Coder

 
Join Date: May 2008
Posts: 34
Thanks: 6
Thanked 0 Times in 0 Posts
reach100 is an unknown quantity at this point
Set and use a variable to control page Colors

Hi There, I would like to build a page that displays a certain image, and background color based on a variable sent in the URL string. Can someone please give me a simple explanation on how to do this?

Here is a link to my test page...
http://dev.tommybaynard.com/sample_page.php?ID=A1

I would like the variable A1 to determine that image 1.jpg will be used, and that #7F8F91 is the background color.

Any suggestions are welcome, thanks.
Rich
reach100 is offline   Reply With Quote
Old 08-08-2008, 12:19 AM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
Simple way.

PHP Code:
<?php
$id 
$_GET['ID'];

switch(
$id){
    case 
'A1':
        
$bgcolor '#7F8F91';
        
$image '1.jpg';
    break;
    
    case 
'A2':
        
$bgcolor '#FF9999';
        
$image '2.jpg';
    break;

    default:
        
$bgcolor '#FFFFFF';
        
$image 'defaultimage.jpg';
}
?>
<html>
<head>
<style>
body{
        background-color:<?php echo $bgcolor?>;
    }
</style>
</head>
<body>
<img src="images/<?php echo $image?>" />
</body>
</html>
Nightfire is offline   Reply With Quote
Users who have thanked Nightfire for this post:
reach100 (08-11-2008)
Old 08-09-2008, 12:15 AM   PM User | #3
reach100
New Coder

 
Join Date: May 2008
Posts: 34
Thanks: 6
Thanked 0 Times in 0 Posts
reach100 is an unknown quantity at this point
Thanks! that worked great for me.
Do you have any idea how I could use this to update a page, WITHOUT having to reload the page? I just want a link to update the background and image on the fly.
Thanks,
Rich
reach100 is offline   Reply With Quote
Old 08-09-2008, 12:39 AM   PM User | #4
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
You'll need to use javascript to do that. Take a look on dynamicdrive or something, there should be a script on there that can be modified
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 PM.


Advertisement
Log in to turn off these ads.