Looking to do an alternating row background color like i have here
http://www.becauseitscool.com/htables22.php
I've looked around, none seem to work with what I already have. I already did it once, but can;t get it to work with a specific query and table that I am using below. It is a plain table with no color in the output echo variables.
What is an easy code to use with the code I have below? And where would it need to go?
<?
while ( $row = mysql_fetch_array($result))
{
echo "<tr><td>$row[against]</td><td>$row[ab]</td><td>$row[h]</td><td>$row[hr]</td><td>$row[rbi]</td><td>$row[doubles]</td><td>$row[triples]</td><td>$row[r]</td><td>$row[sb]</td></tr>";
}
?>
---------------------------------------
Thanks in advance you guys rock!!!
Incorporating Alternate bg color rows
Moderator: General Moderators
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
You actually alternate a variable for every row...
First you set up the variable "color" before the while() loop. Then, in your <tr> tag, put in 'bgcolor=\"$color\"', so it'll set the whole row that specified color. Then, switch the colors around using the if() statement above.
Did this help any?
Code: Select all
<?
$color = "#F0F0F0";
while ($row = mysql_fetch_array($result))
{
echo "<tr bgcolor="$color"><td>$row[against]</td><td>$row[ab]</td><td>$row[h]</td><td>$row[hr]</td><td>$row[rbi]</td><td>$row[doubles]</td><td>$row[triples]</td><td>$row[r]</td><td>$row[sb]</td></tr>";
if($color == "#F0F0F0") {
$color = "#FFFFFF";
} else {
$color = "#F0F0F0";
}
}
?>Did this help any?
oh I am sorry, if I looked at the link I would understand what you wanted.
Well, this is confusing to me, perhaps this (untested)
I think that'll work fo rya
edit - well I think phice method is more clear. lol
Well, this is confusing to me, perhaps this (untested)
Code: Select all
<?php
for($i=1; $i<10; $i++)
{
// thats your loop, heres your if statement
if($i%2 == 0){
$bg = "#0000FF";
}else{
$bg = "#FFFFFF";
}
// notice the %, this tells the server to divide the results by two, if I am correct, which creates two loops in effect
use the llop like this:
echo "<tr bgcolor="$bg"><td >$i</td></tr>";
?>edit - well I think phice method is more clear. lol
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
