#native_company# #native_desc#

Using PEAR’s HTML_Table Class Page 4

By Andy Nortrup
on August 18, 2003

A Few Last Tricks
And before we close here are few last tricks that come along with this very useful class.

Alternating Rows

One of the most common tasks when creating tables containing database output is alternating colors to make it easier to read. The HTML_Table class makes this easy to do, using the altRowAttributes function. Using our example from before the function works like this:

//..database retrieval... 

while($row mysql_fetch_array($result)) {
$contents = array($row['name'], $row['email'], $row['phone']);
//alternate between 2 colors
$attributes1 bgcolor #336699;
$attributes2 bgcolor #COCOCO;


This will result in the rows switching colors with every row, starting with the second (as our first row is a header).
Outputting to HTML
Another useful feature is the toHtml() function which works much the same as the display function but instead returns the html rather than outputting directly. This is useful if you are building the table in a function or need to display the table in a place other than where you built it.
In parting, I hope that I have shown you the benefits of the HTML_Table class. There are several other functions which I felt were beyond the scope of this introduction but I very much encourage you to browse the code yourself and find them. I think you will find the documentation to be very well done.