by skyvia
2 replies
I have add bars on my site and would like the to have them change every time the page is refreshed. Say I have room for 3 adds but have 6 diff adds. How can I make it random what comes up?
#add #bar #site
  • Profile picture of the author cuddy
    There are many ways you can do this. One is with only javascript and the other is with php with or without mysql. There are many free ad rotation scripts out there - simply google it and you will find your solutions.
    {{ DiscussionBoard.errors[4299037].message }}
    • Profile picture of the author eric1508
      You can do this pretty easily with some simple PHP code. Here is a modified snippet of code that I've used before to randomly display Product Testimonials (I modified it to better suit your needs in case you want to give it a try):

      PHP Code:
      // Chooses a random number between 1 and 6.
       
      Rand1); 
      // Displays an ad based on the random number.
      switch(  )
      {
          case 
      1:
          echo 
      '[AD1 CODE HERE]';
          break;
          case 
      2:
          echo 
      '[AD2 CODE HERE]';
          break;
          case 
      3:
          echo 
      '[AD3 CODE HERE]';
          break;
          case 
      4:
          echo 
      '[AD4 CODE HERE]';
          break;
          case 
      5:
          echo 
      '[AD5 CODE HERE]';
          break;
          case 
      6:
          echo 
      '[AD6 CODE HERE]';
          break;

      EDIT: For some reason the variable keeps getting stripped in my post. This is what the top part of that code should look like:

      // Chooses a random number between 1 and 6.
      $num = Rand( 1, 6 );
      // Displays an ad based on the random number.
      switch( $num )

      Eric
      {{ DiscussionBoard.errors[4302228].message }}

Trending Topics