Location: PHPKode > scripts > dbHtmlTable > dbHtmlTable.class.extend.php
    This file is entirely optional. It shows how you could extend 
    the dbHtmlTable class to implement themes, or use a data 
    source other than MySQL.


    This example adds a new method setTheme(), allowing 
    you to create tables with a predetermined set of options. 
    Sample usage:
        $HtmlTable = new MyDbHtmlTable('select * from mytable');

class MyDbHtmlTable extends dbHtmlTable {

public function setTheme($ThemeName)
        case 'mytheme':
                'TableAttr'   => 'border="0" cellspacing="0"',
                'emptyvalue'  => '<span style="color:#888;">(empty)</span>',
                'nullvalue'   => '<span style="color:#888;">-null-</span>',
                'OddRowClass' => 'odd',
                'EvenRowClass'=> 'even',
                'rownumber'   => '#',
                'ShowFooter'  => true
        case 'clean': default:

    By default, dbHtmlTable uses MySQL as the data source. 
    This example shows how you can change the class to use a 
    different data source (in this case, PostgreSQL). 
    To do this you need to define three methods:

        must set class properties dbRowCount, dbColumnCount and 
        return a query result resource, which will later be 
        passed to the other two methods.

        given the resource returned by _dbGetResultset,
        must return an enumerated array of field names

        given the resource returned by _dbGetResultset,
        must return an array containing the first row of data, 
        and on subsequent calls the next row. The returned 
        array must be enumerated, not associative (ie indexed 
        by  field position not field name)

class PostgreTable extends dbHtmlTable {

protected function _dbGetResultset()
    $result = pg_query($this->dbSql);
	$this->dbRowCount = pg_num_rows($result);
	if(0==$this->dbRowCount) return false;
	$this->dbColumnCount = pg_num_fields($result);
    return $result;

protected function _dbGetRow($resultset)
    { return pg_fetch_row($resultset); }

protected function _dbGetFieldnames($resultset)
    for ($i = 0; $i < $this->dbColumnCount; $i++) 
        { $FieldName[] = pg_field_name($resultset, $i); }
    return $FieldName;

    You could even amend example 2 to use a file, an array or 
    XML data as the data source. (I haven't actually tried this, 
    which is why there's no sample code!)
    The "sqlString" passed to the class could be a filename,
    an array, or any other data. You would just need a local 
    property to keep track of which row should be returned next
    by the _dbGetRow() method.
    The "query result resource" returned by _dbGetResultset() and
    used by _dbGetFieldnames() and _dbGetRow() is not checked in
    any way, so it could be anything.

Return current item: dbHtmlTable