Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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>

  • Users who have thanked Nightfire for this post:

    reach100 (08-11-2008)

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •