By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,918 Members | 1,557 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,918 IT Pros & Developers. It's quick & easy.

the function to switch values ie for alternating between 2 colors in table display

P: n/a
Hi all!

What is the php function called which allows you to alternate between
two values? I've completely forgotten it and my searches in php.net
have not been fruitful!

Kind regards

Marc

Jul 12 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
it has something like this in it somehere:

for($i=0; $i<10; $i++) {
echo $i % 2 ? $catodd : $cateven;
}

monomaniac21 wrote:
Hi all!

What is the php function called which allows you to alternate between
two values? I've completely forgotten it and my searches in php.net
have not been fruitful!

Kind regards

Marc
Jul 12 '06 #2

P: n/a
Message-ID: <11*********************@s13g2000cwa.googlegroups. comfrom
monomaniac21 contained the following:
>
What is the php function called which allows you to alternate between
two values? I've completely forgotten it and my searches in php.net
have not been fruitful!
There is a function?

I usually just do something like this

$rowstyle=($count%2!=1)?" style='background-color:#ddd'":"
style='background-color:#fff'";
$count++;

for each table row.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 12 '06 #3

P: n/a

I prefer

$linestyle = 1

While (criteria)
{
.......
$lineclass = "lineclass" . $linestyle;
<TR class = $lineclass><TD></TD></TR>;

$linestyle = 1 - $linestyle;
}

and set up two classes called lineclass0 and lineclass1

personally I think it is easier to read and control.

Jul 12 '06 #4

P: n/a
monomaniac21 wrote:
it has something like this in it somehere:

for($i=0; $i<10; $i++) {
echo $i % 2 ? $catodd : $cateven;
}
Just use an array:

$class = array('blue', 'red');

echo $class[$i%2];

Jul 12 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.