PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
meander
Forum Commoner
Posts: 26 Joined: Sun Oct 10, 2004 3:09 pm
Post
by meander » Sun Oct 10, 2004 10:00 pm
i got this code out of a book to alternate the colors of the table rows
Code: Select all
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$bg = ($bg=='dddddd' ? 'ffffff' : 'dddddd');
echo "<tr bgcolor="", $bg, "" ><td align="left">$row[0]</td><td align="left">$row[1]</td><td align="left">$row[2]</td><td align="left">$row[3]</td></tr>\n";
}
and i was wondering what it actually does? it seems like it does something like if $bg = dddddd then switch it to ffffff and vice versa. am i completely wrong about this?
meander
Forum Commoner
Posts: 26 Joined: Sun Oct 10, 2004 3:09 pm
Post
by meander » Sun Oct 10, 2004 10:04 pm
i also forgot to ask, can this same method be applied to different things? like anything that you would need to alternate?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Oct 10, 2004 11:07 pm
yes. it flips between 2 colors for the rows output.
This kind of thing works for plenty of other things.
meander
Forum Commoner
Posts: 26 Joined: Sun Oct 10, 2004 3:09 pm
Post
by meander » Sun Oct 10, 2004 11:18 pm
so then if i wanted to flip back and forth between a variable i could just do
Code: Select all
$var = ($var=='one' ? 'two' : 'one');
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Oct 10, 2004 11:19 pm
that's one way of doing it, yes.