Tuesday, 6 December 2011

Create table parti-colored in PHP


Create table parti-colored

When select the data in the database to create a table. A row, alternating colors to make
available information in the table more easily.

Example

<style>
.odd{background:#CCC;}
.even{background:#FFF;}
</style>

<table>
<?php
$bg = "odd";
for($i=0;$i<10;$i++)
{
    echo "<tr class='$bg'>";
    echo "<td>&nbsp;</td>";
    echo "</tr>";
     if($bg == "odd")
    {
        $bg = "even";
    }
    else
    {
        $bg = "odd"; 
    }
}
?>
</table>

No comments:

Post a Comment

Visual comparison of the two methods, creating a simple table.

Option 1, using PHP: // PHP $html = '<table>' ;     foreach ( $data as $row ) {     $html .= '<tr>...