Dynamic Table?
Posted: Thu Feb 18, 2010 9:11 pm
I want to create a dynamic table in php that it 1st row color is blue and 2nd row color is white and so on.
How it is possible.
Adil
How it is possible.
Adil
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
color = blue
for each row in table {
print row with color
if color == blue then color = white else color = blue
}Code: Select all
<?php
$k = 1;
for()
{
if ($k % 2 == 0)
$color = "blue";
else
$color = "white";
$k++;
}
?>
Code: Select all
/* CSS */
tr:nth-child(odd) {
background-color: blue;
}
tr:nth-child(even) {
background-color: white;
}Code: Select all
<?php
print "<table>";
for($i=0; $i<4; $i++){
$color = ($i % 2) ? "white" : "blue";
print "<tr><td>{$color}</tr></td>";
}
print "</table>";
?>