Jump to content

alternating row colors...


boo_lolly

Recommended Posts

I have a while loop that outputs an HTML table. i need iit to alternate row colors. i'm sure there's many ways to skin this cat, but how would i incorporate it within the provided code below?
[code]
<?php
while($s = mysql_fetch_array($sQuery)){
echo "\t<tr>\n".
                    "\t\t<td>". $s[id] ."</td>\n".
                    "\t\t<td>". $s[name] ."</td>\n".
                    "\t\t<td align=\"right\"><p><a href=\"index.php?site=". $site ."&zone=". $zone ."&action=manu&editmanu=true&id=". $s[id] .">\n".
    "<img src=\"images/button_edit.gif\" border=\"0\" alt=\"Edit\"></a>\n".
                    "<a href=index.php?site=". $site ."&zone=". $zone ."&action=manu&delete=true&id=". $s[id] .">\n".
    "<img src=\"images/button_delete.gif\" border=\"0\" alt=\"Delete\"></a></p>\n".
                    "\t\t</td>\n".
            "\t</tr>\n";
}
?>
[/code]
many thanks.
Link to comment
https://forums.phpfreaks.com/topic/32888-alternating-row-colors/
Share on other sites

[code]
<?php
            $i = 0;
while($s = mysql_fetch_array($sQuery)){
            ++$i;
            $bgcolor = "";
            if( $i % 2 == 0 )
            {
              $bgcolor = "red";
            } else {
              $bgcolor = "yellow";
            }

echo "\t<tr bgcolor=\"$bgcolor\">\n".
                    "\t\t<td>". $s[id] ."</td>\n".
                    "\t\t<td>". $s[name] ."</td>\n".
                    "\t\t<td align=\"right\"><p><a href=\"index.php?site=". $site ."&zone=". $zone ."&action=manu&editmanu=true&id=". $s[id] .">\n".
    "<img src=\"images/button_edit.gif\" border=\"0\" alt=\"Edit\"></a>\n".
                    "<a href=index.php?site=". $site ."&zone=". $zone ."&action=manu&delete=true&id=". $s[id] .">\n".
    "<img src=\"images/button_delete.gif\" border=\"0\" alt=\"Delete\"></a></p>\n".
                    "\t\t</td>\n".
            "\t</tr>\n";
}
?>
[/code]
thanks dbo! i got this on my own... VERY similar.
[code]
<?php
$color = 0;
while($s = mysql_fetch_array($sQuery)){
if($color % 2 == 0){
$alt_color = "FFFFFF";
}else{
$alt_color = "DDDDDD";
}
echo "\t<tr bgcolor=\"". $alt_color ."\">\n".
                    "\t\t<td>". $s[id] ."</td>\n".
                    "\t\t<td>". $s[name] ."</td>\n".
                    "\t\t<td align=\"right\"><p><a href=\"index.php?site=". $site ."&zone=". $zone ."&action=manu&editmanu=true&id=". $s[id] .">\n".
    "<img src=\"images/button_edit.gif\" border=\"0\" alt=\"Edit\"></a>\n".
                    "<a href=index.php?site=". $site ."&zone=". $zone ."&action=manu&delete=true&id=". $s[id] .">\n".
    "<img src=\"images/button_delete.gif\" border=\"0\" alt=\"Delete\"></a></p>\n".
                    "\t\t</td>\n".
            "\t</tr>\n";
$color++;
}
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.