Kamala - Sport Betting Systems - Cyberax Tech Web Hosting India - Air Jordans - Jigsaw Puzzles

PDA

View Full Version : changing row colors


mnymkr
Oct 13th 2007, 8:53 am
I am dumping a database table....it has 4 columns and about 260 rows


i would like for the each row in a set of 3 to be a different shade of grey


row1 - grey
row2 - light grey
row3 - darkgrey

repeat


what the best way to accomplish this?

nico_swd
Oct 13th 2007, 9:26 am
function get_color()
{
static $current = 0;
static $colors = array(
'#666666',
'#999999',
'#CCCCCC'
);

return $colors[$current++ % sizeof($colors)];
}



Set the colors in the function itself. As many as you want.

And then in your loop just do:



while (/* condition */)
{
$background = get_color();

// Do whatever with background
}

mnymkr
Oct 13th 2007, 10:42 am
that is amazing

you know i know so crazy things, like how to grow alumina nanotube and attach proteins but sometimes the elegance in php amazes me


thank you thank you

and teach me teach me LOL

nico_swd
Oct 13th 2007, 2:08 pm
It was an interesting programming experience for me too. :) I was trying to keep the function as short as possible.

It took me a moment to think of using the modulus operator.

mnymkr
Oct 15th 2007, 11:28 am
yeah that is really cool. worked perfectly