Background image rotation

Discussion in 'HTML & Website Design' started by Shimurai, Jun 3, 2009.

  1. #1
    Hello,

    I've been searching for a code that can change my website background image randomly when someone reloads the page but couldn't find anything.

    What I'm exactly looking for is for a code that will change the background of a table randomly to another one when someone reloads the page, but, I don't want it to change every time someone reloads the page, as I said, I need it to be randomly, and I mean that sometimes the background can just stay at the same one.

    For now I'm using a single image as background, without a rotating code:

    <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" 
    background="./template/default/images/bg.jpg" style="background-repeat:no-repeat; background-position:center; background-position:top">
    Code (markup):
    What I want to do is something that will change that background path "./template/default/images/bg.jpg" to another one, like "./template/default/images/bg2.jpg" or something like that when someone reloads the page.

    Thanks in advance.
     
    Shimurai, Jun 3, 2009 IP
  2. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Sorry for double posting but I found a solution.

    I just used this simple PHP code:

    
    $array[0] = './template/default/images/site_bg.jpg';
    $array[2] = './template/default/images/bg.jpg';
    shuffle($array);
    
    Code (markup):
    and changed the table code to this one:
    
    <table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" 
    background=\" ". "$array[0]" ." \" style=\"background-repeat:no-repeat; background-position:center; background-position:top\"> 
    
    Code (markup):
    and that did the rotation I needed. for this i searched on google for " background change onload " . :)
     
    Shimurai, Jun 3, 2009 IP
  3. 3drendering

    3drendering Peon

    Messages:
    260
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have no Idea about it Please find a good PHP Programmer and do this...
     
    3drendering, Jun 4, 2009 IP