Here is a compact generic function by john.ellingsworth that generates a table from a PEAR DB result set. It even uses column names as HTML table column headings.

A hint: to better format a table when there is a null value in the resultset, add a ‘nbsp;’ character to a table cell before a field value.