My favorites | Sign in
Project Logo
                
Search
for
Updated May 13, 2008 by nsbucky
Labels: Featured
DatabaseStuff  
using adodb and paging recordsets

Be sure to check out the DB example module in the downloads section.

Page a recordset

require 'init.php';

$urls = array(
              '#^$#'     => 'dbtest'              
             );

class dbtest {
    private $db;
    function __construct()
    {   
        include 'webphp/lib/adodb5/adodb-exceptions.inc.php';
        include 'webphp/lib/adodb5/adodb.inc.php';
        $db = NewADOConnection("mysql://root:root@localhost/inbox_test");
        $this->db = $db;
    }
    
    function GET($p)
    {   
        include 'webphp/lib/recordsetpager.php';
        include 'webphp/lib/recordsettable.php';
        $sql = 'select id, first_name, last_name from inbox_leads order by id';

        /*
        $pager = new RecordSetPager($this->db, $sql,10);
        $rs = $pager->getRecords();
        
        echo "<br>Nav: ".$pager->navigation();
        echo "<br>Page Count: ".$pager->pageCount();
        echo "<br>Total Rows: ".$pager->totalRows();
        echo "<h3>Rows</h3>";
        foreach ($rs as $row) {
            print_r($row);
            echo "<br>";
        }
        */
        
        // automatically create a table
        echo new RecordSetTable(new RecordSetPager($this->db, $sql,10));
    }
}

try {    
    Web::run($urls); 
} catch (RequestErrorException $e) {    
    $e->ViewError();
}

Sign in to add a comment
Hosted by Google Code