Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

If Then Else Statement to Randomly Show 2 Ads

Posted on 2008-06-09
1
Medium Priority
?
763 Views
Last Modified: 2013-12-25
I have on page on a site I am working on that is a PHP page.  At the top it has an ad spot that is rotating 2 different ads.  It is working by coming up with a random number, then depending on whether it is even or odd, it displays one of the two ads.

Here is the php code:

<? if(rand(0,10)<5){ ?>
  <script type="text/javascript">
      google_ad_client = "pub-29xxxxxxxx";
      google_ad_width = 120;
      google_ad_height = 600;
      google_ad_format = "120x600_as";
      google_ad_type = "text_image";
      google_ad_channel ="6xxxxxxxxx";
      google_color_bg = "353269";
      google_color_link = "FFFFFF";
      google_color_text = "e0e0e0";
      google_color_url = "b8b8b8";
</script>
  <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  <? }else{ ?>
  <a href="http://www.someadsite.com" target="_blank"><img src="http://www.somewebsite.com/images/web-ad-someadsite.jpg" width="120" height="620" border="0" /></a>
  <? } ?>

I need to pull off something like this, but on a standard .html page.  Is there a way to do this using javascript or straight html?
0
Comment
Question by:TheShaner
1 Comment
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 21749412
Like this
  <script type="text/javascript">
if (Math.floor(Math.random()*2) ==0) { 
      google_ad_client = "pub-29xxxxxxxx";
      google_ad_width = 120;
      google_ad_height = 600;
      google_ad_format = "120x600_as";
      google_ad_type = "text_image";
      google_ad_channel ="6xxxxxxxxx";
      google_color_bg = "353269";
      google_color_link = "FFFFFF";
      google_color_text = "e0e0e0";
      google_color_url = "b8b8b8";
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><\/script>');
  }else{ 
      document.write('<a href="http://www.someadsite.com" target="_blank"><img src="http://www.somewebsite.com/images/web-ad-someadsite.jpg" width="120" height="620" border="0" /></a>');
  }
</script>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question