Hi guys,

Not sure if this can be done in PHP but I'm looking at giving users an option to choose a background image from a list ie when they click on a url it changes. The best way I can explain it is

http://www.kennetisland.co.uk/

If you click on the links to change of scene on the left hand column, you'll hopefully see what I mean.

Can this be done in PHP? I've tried googling it, searching on various forums but can't seem to find anything..

Any ideas would be appreciated..

Cheers

    Yes, it can be done. The website you linked to probably just checks the incoming variable, and switches accordingly.

      Here is a very simple way to do it. (the file is named bgtest.php)

      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <title>background test</title>
      <?php
      $bgimage = $_REQUEST['bgimage'];
      
      switch($bgimage) {
      
      case 1:
      	$bground = "../images/large.jpg";
      break;
      case 2:
      	$bground = "../images/index_01.gif";
      break;	
      case 3:
      	$bground = "../images/blueball.gif";
      break;
      default:
      	$bground = "../images/large.jpg";
      break;
      }
      
      ?>
      <style type="text/css">
      <!--
      body {	
      	background-image: url(<?php echo "$bground";?>);
      	background-repeat: no-repeat;
      	background-position:center;
      }
      -->
      </style></head>
      <body>
      <p>Choose Background Image:</p>
      <form name="form1" method="post" action="bgtest.php">
        <p>
          <input name="bgimage" type="radio" value="1"> 
        Background 1 <br>
        <input name="bgimage" type="radio" value="2">
      Background 2 <br>
        <input name="bgimage" type="radio" value="3">
      Background 3 </p>
        <p>
          <input type="submit" name="Submit" value="Submit">
        </p>
      </form>
      <p>&nbsp;</p>
      </body>
      </html>
      

      It will default to "large.jpg". You can put previews, or use a drop down menu, or whatever you like.

      Regards,

      Michael (big.nerd)

        Write a Reply...