Simple Content Rotator On Page Load

Discussion in 'HTML & Website Design' started by Webgold, Dec 16, 2009.

  1. #1
    Hey

    Does anyone know how I can change an area of content on each page load?

    Basically I want to swap utube videos on each page load, so visitors don't see the same video each time. I am only going to have about 3 videos to swap between.

    I have done many searches but can't seem to find anything simple, also it doesn't need to be on a timer, just on each page load it swaps the video?

    Thank you for any help :)
     
    Webgold, Dec 16, 2009 IP
  2. Webgold

    Webgold Peon

    Messages:
    193
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Wow since posting this, the question has already been indexed by google.
     
    Webgold, Dec 16, 2009 IP
  3. LeetPCUser

    LeetPCUser Peon

    Messages:
    711
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is an idea, load one of the three videos at random. This gives the viewer a 1/3 chance of viewing it the first time and a 1/9 chance of seeing it again. You will need PHP for this. See code below.

    
    <?php
     //set a variable equal to a random number between 1 and 3
     $random = rand(1, 3);
    
     //switch the random number (for the check on what it returned)
     switch ($random)
     {
      //if the number is one, set the variable url equal to the first video
      case 1:
       $url = 'http://yoursite.com/video1.flv';
       break;
    
      //if the number is two, set the variable url equal to the second video
      case 2:
       $url = 'http://yoursite.com/video2.flv';
       break;
    
      //if the number is three, set the variable url equal to the third video
      case 3:
       $url = 'http://yoursite.com/video3.flv';
       break;
     } //end switch
    ?>
    
    <embed src="<?php echo $url; ?>"></embed>
    
    Code (markup):
    Not sure of the file location or how you are embedding. This is just an example. By no means did I verify the embed. Hope this helps!
     
    LeetPCUser, Dec 16, 2009 IP