...

View Full Version : Set and use a variable to control page Colors



reach100
08-07-2008, 11:11 PM
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

Nightfire
08-08-2008, 01:19 AM
Simple way.



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

reach100
08-09-2008, 01:15 AM
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

Nightfire
08-09-2008, 01:39 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum