Worcester Landscaping Company - Mobile Phones - Mortgages - Investing - Personal Finance

PDA

View Full Version : Rotating two bits of code


blueuniverse
Dec 10th 2004, 10:47 am
In the corner of my page I have an ad space, but I want to rotate this between the code from Trade Doubler and the code from Commission Junction. Both are javascript codes (you'll know what they look like if you use them, basically they're just jscript pools).

Anyway, the page is vbulletin so PHP enabled (hence why I didn't put it in either the php or javascript forum, because I could use both to rotate the code).

I only have 2 bits of code I need to rotate, but it is code not images.

Does anybody know how I could achieve this?

disgust
Dec 10th 2004, 11:20 am
<?

$rand = rand(1,2);

if ($rand == 1) {
echo this code
}
elseif ($rand == 2 {
echo this code
}

?>

you can change the ",2" bit in the rand statement to have more than two bits of code, and then just add more elseif's too if you like.

blueuniverse
Dec 10th 2004, 11:46 am
Ahhh, I've just realised that it is actually going to have to be javascript, beacause the header template file in vB won't accept php code :S

Gandalph
Oct 17th 2005, 11:46 am
ahh, just a tiny bit of refinement, so you can post your adsense code and other codes in here without php proofing them ;)

<?php
// change the ",2" bit in the rand statement to have more than two bits of code, and add more elseif's if you like
$rand = rand(1,2);

if ($rand == 1){
?>

place first html/javascript ad code here

<?php
} elseif($rand == 2){
?>

place 2nd html/javascript ad code here

<?php
}
?>

maro
Oct 18th 2005, 7:14 am
If you want it entirely in javascript:

random_num = Math.round(Math.random());
if (random_num == 0)
{
// What you want to do 1
}
else
{
// What you want to do 2
}

creepah
Dec 22nd 2005, 11:02 am
ahh, just a tiny bit of refinement, so you can post your adsense code and other codes in here without php proofing them ;)

<?php
// change the ",2" bit in the rand statement to have more than two bits of code, and add more elseif's if you like
$rand = rand(1,2);

if ($rand == 1){
?>

place first html/javascript ad code here

<?php
} elseif($rand == 2){
?>

place 2nd html/javascript ad code here

<?php
}
?>


thanks for that bit of code very helpful :)

noppid
Dec 22nd 2005, 11:33 am
If there are only two, make it boolean.


if( rand(0,1) )
{
// $display_var = evaled code for 1
}
else
{
// $display_var = evaled code for 0
}


vBulletin 3.5.x hook global_start
vBulletin 3.0.x php_include_start template