PEAR Manual
Prev |  | Next

# Example - Quick

Example - Quick -- Quickly bind a database record set

## Description

### Binding a result set

To begin binding an existing record set of data to a DataGrid you can easy use the bind() method.

Example 55-1. Simple Database Binding Example
    <?php
    require 'Structures/DataGrid.php';

    // Get my data
    $result = mysql_query('SELECT * FROM users');
    while ($record = mysql_fetch_assoc($result)) {
        $dataSet[] = $record;
    }

    // Print the DataGrid
    $dg =& new Structures_DataGrid();
    $dg->bind($dataSet);
    $dg->render();
    ?>
Additionaly you can use the bindDataSource for more complex datatypes such as a DB_Result object:
    <?php
    require 'Structures/DataGrid.php';
    require 'Structures/DataGrid/DataSource.php';

    $dg =& new Structures_DataGrid();

    // Get my data
    $result = $db->query('SELECT * FROM users');

    // Bind to DataGrid
    $data = Structures_DataGrid_DataSource::create($result);
    $dg->bindDataSource($data);

    // Print the DataGrid
    $dg->render();
    ?>

Prev | Home | Next
Column Formatter | Up | Example - Complex