PDA

View Full Version : Rotating Divs



Jordan,
16-06-2009, 01:00 PM
Well i have a box then i want everytime somone refresh it changes colour

I have Blue, Green red

Divs

bluetop, bluemid, bluebot,
greentop, greenmid, greenbot
redtop, redmid, redbot

is there anyway i can do this?

DeejayMachoo$
16-06-2009, 01:33 PM
Something like this...?


<?php
$random_color = rand(1,3);

if ($random_color == 1) {
$color = 'blue';
} elseif ($random_color == 2) {
$color = 'green';
} else {
$color = 'red';
}

echo '<div class="'.$color.'top"></div>';
echo '<div class="'.$color.'mid"></div>';
echo '<div class="'.$color.'bot"></div>';

?>

AlexOC
16-06-2009, 08:38 PM
Something like this...?


<?php
$random_color = rand(1,3);

if ($random_color == 1) {
$color = 'blue';
} elseif ($random_color == 2) {
$color = 'green';
} else {
$color = 'red';
}

echo '<div class="'.$color.'top"></div>';
echo '<div class="'.$color.'mid"></div>';
echo '<div class="'.$color.'bot"></div>';

?>

That would cause the same colour to be shown in a row occasionally?

There would be a way via Cookies where it will choose a different colour than the last time.

That is if your bothered about the same colour showing.

DeejayMachoo$
16-06-2009, 09:44 PM
That would cause the same colour to be shown in a row occasionally?

There would be a way via Cookies where it will choose a different colour than the last time.

That is if your bothered about the same colour showing.



<?php
session_start();
$color = $_SESSION['color'];

if ($color == '') {
$color = 'blue';
$_SESSION['color'] = 1;
} elseif ($color == 1) {
$color = 'green';
$_SESSION['color'] = 2;$
} elseif ($color == 2) {
$color = 'red';
$_SESSION['color'] = '';
}

echo '<div class="'.$color.'top"></div>';
echo '<div class="'.$color.'mid"></div>';
echo '<div class="'.$color.'bot"></div>';
?>

Want to hide these adverts? Register an account for free!