Simple Ad Rotation Script

Started on the old forum in October 2009 · view the original in the archive · old links redirect here

No replies · 689 views · started 17 years ago · 1 min read

riderz Lead · 975 posts #1

In this script (very easy script), we have 3 ads for rotation first ad we want it to display 70% second ad we want to display 20% and the last one we want to display 10%

What to do

  1. Random number 1-100
  • if result = 1-70 (we have opportunity to display ad 1, 70%)
  • if result = 71-90 (we have opportunity to display ad 2, 20%)
  • if result = 91-100 (we have opportunity to display ad 3, 10%

Example

In this script use rand(1, 100); to random number between 1 -100 and keep result in variable name "$result_random" if result = 85 ad 2 will display.

<?php

// random number 1 - 100 
$result_random=rand(1, 100);

// if result less than or equal 70, display ad 1 (70%)
if($result_random<=70){
echo "Display ad1";
}

// if result less than or equal 90, display ad 2 (20%)
elseif($result_random<=90){
echo "Display ad2";
}

// if result less than or equal 100, display ad 3 (10%)
elseif($result_random<=100){
echo "Display ad3";
}

?>

Jacques jacques@gw-designs.co.za http://coding.biz.tm Come join and lets make it a place to learn all the noobies how to code


NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close