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
Dynamic Table?
Moderator: General Moderators
Re: Dynamic Table?
Code: Select all
color = blue
for each row in table {
print row with color
if color == blue then color = white else color = blue
}Re: Dynamic Table?
Try this
Code: Select all
<?php
$k = 1;
for()
{
if ($k % 2 == 0)
$color = "blue";
else
$color = "white";
$k++;
}
?>
Re: Dynamic Table?
There is also the CSS3 :nth-child() pseudo-class selector.
The PHP solution is more compatible with older browsers, though.
Edit: This post was recovered from search engine cache.
Code: Select all
/* CSS */
tr:nth-child(odd) {
background-color: blue;
}
tr:nth-child(even) {
background-color: white;
}Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 5:14 pm, edited 1 time in total.
Re: Dynamic Table?
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>";
?>