PDA

View Full Version : PHP Tutorial - Ad Rotation Script


fedqa
02-26-2008, 02:46 AM
With this script, you will be able to have 3 banners/ads in a rotation showing one more than the other.

First Banner we want it to display 70%.
Second Banner we want to display 20%.
Third Banner we want to display 10% .


Code:
<?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 "Ad 1 link";
}

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

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

?>
_________________
banner sign stands (http://www.everythingbanners.com) trade show display (http://www.everythingdisplays.com)

Fishnagles
02-26-2008, 07:22 AM
That looks pretty good.... I've been using a javascript rotation scripts but it doesn't let you control rotation frequency, it's just completely random... This looks better.

madhuri_vats
07-22-2008, 08:16 AM
Great work man...........

Web Design Company (http://www.chandeltechnologies.com) | Asp.Net Programmers (http://www.radixinfosolutions.com)| web designers Delhi (http://www.aspireinfosys.com)

marshtric
12-13-2008, 03:49 AM
thank u
for the code nnippet

Fishnagles
12-13-2008, 09:33 AM
Anyone use this yet...? Looks like a great script.

Janepenelope
04-18-2009, 08:03 AM
With this script, you will be able to have 3 banners/ads in a rotation showing one more than the other.

First Banner we want it to display 70%.
Second Banner we want to display 20%.
Third Banner we want to display 10% .


Code:
<?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 "Ad 1 link";
}

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

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

?>
_________________
banner sign stands (http://www.everythingbanners.com) trade show display (http://www.everythingdisplays.com)

Really then it will be very helpful to me, let me try this