Jump to content

alternative table row coloring with css


ted_chou12

Recommended Posts

i think php is better if you have so many rows, here is a simple one in php
hope this helps!!

[code]

<?php 

$query = "SELECT * FROM table";
$result = $dbh->query($query);

// output query into a table
echo "<br><br><table border=0>\n";

// fetch rows as object    example if you only have 2 rows: printf ("%s, %s\n", $row->rowname1, $row->rowname2);
while($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
{

// alternate table color output
if($x%2): $color = "#eee"; else: $color = "#cecece"; endif;

// output row values, rows are fetch as object
printf("<tr><td style=\"background-color: ".$color. "\">%s</td><td style=\"background-color: ".$color."\">%s</td></tr>\n", $row->rowname1, $row->rowname2);
$x++;
}

echo "</table>\n";

?>


[/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.