Click to See Complete Forum and Search --> : Table - Alternating Colors
GAF123
11-05-2004, 09:41 AM
I WOULD LIKE TO DISPLAY ROWS IN A TABLE WITH ALTERNATING
COLORS ON EACH LINE (EX: 1ST LINE - RED, 2ND LINE - BLUE, 3RD LINE
RED, 4TH LINE BLUE - ETC)
IS THERE AN EASY WAY TO DO THIS?
THANK YOU
NogDog
11-05-2004, 09:54 AM
You can use CSS to control the look of each row:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head><title>alternate rows</title>
<style type=text/css>
.red {
color: red;
background-color: silver;
}
.blue {
color: blue;
background-color: aqua;
}
.yellow {
color: yellow;
background-color: navy;
}
</style>
</head>
<body>
<table border=1 cellspacing=0 cellpadding=3>
<tr class=yellow><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>
<tr class=red>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
<td>Row 1, Column 3</td>
</tr>
<tr class=blue>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
<td>Row 2, Column 3</td>
</tr>
<tr class=red>
<td>Row 3, Column 1</td>
<td>Row 3, Column 2</td>
<td>Row 3, Column 3</td>
</tr>
<tr class=blue>
<td>Row 4, Column 1</td>
<td>Row 4, Column 2</td>
<td>Row 4, Column 3</td>
</tr>
</table>
</body>
</html>
GAF123
11-05-2004, 10:23 AM
MY TABLE HAS UP TO 99 OCCURENCES
<xsl:for-each select="//s1-table">
<tr>
<td><xsl:value-of select="s1-desc"/></td>
</tr>
SINCE I DON'T DISPLAY EACH ROW SEPARATELY
I AM NOT ABLE TO MODIFY THE COLOR OF EACH ROW AS IT DISPLAYS
THANK YOU
NogDog
11-05-2004, 10:46 AM
I am not familiar with the "xsl" method. If I were doing it in PHP, I'd do something like:
$row = 1;
while($result = mysql_fetch_array($query))
{
echo "<tr class=";
if($row++ % 2 == 0) # red if even, else blue
{
echo "red>";
}
else
{
echo "blue>";
}
foreach($result as $value)
{
echo "<td>$value</td>
}
echo "</tr>\n";
}
DaveSW
11-06-2004, 06:27 AM
GAF123 WILL YOU PLEASE STOP SHOUTING
i.e. please turn caps lock off before posting any more replies, as in web etiquette capitals equate to shouting.
Thank you.