JDT

 

FREE Downloads
Articles
Tutorials

 

Alternate the Colour of Rows in a Table


Here is a script template you can use to alternate the colours of rows in an HTML table that is derived from data extracted from a MySQL database table.

The script uses a mixture of HTML and PHP code to create an HTML table populated from a MySQL database table.

<?php
// Select data from database table
$result = @mysql_query("select * from database table");

// Start HTML table
print "<table><tr><td>Table Heading</td></tr>\n";

// Define the two colors for the alternating rows of the table
$color1 = "#E0F0F0";
$color2 = "#EEEEEE";

// Set row counter to zero
$row_count = 0;
// Create the table rows
while ($row = @mysql_fetch_assoc($result)){

    $table_item = $row['table_item'];

    //Alternate the colors between the two colors defined above
    $row_color = ($row_count % 2) ? $color1 : $color2;

    // Start row
    print "<tr bgcolor=\"$row_color\">\n";

    print "<td>$table_item</td>\n";

    // End row
    print "</tr>\n";

    // Add 1 to the row count
    $row_count++;

}

// End HTML table
print "</table>\n";
?>


Author: John Dixon
John Dixon Technology Ltd







Go back to MySQL Tutorials home page

Go back to Tutorials home page



Earnings Tracker is John Dixon Technology's FREE accounting / bookkeeping software tool.

Aimed at contractors and freelancers, Earnings Tracker enables you to perform bookkeeping and accounting tasks, helping you to keep track of your company's revenue and spending.

The software enables invoice amounts, expenses, pension contributions, and salaries to be recorded, and calculates the amount of corporation tax due, and the dividend distributions that can be made to shareholders.

The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 


JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions