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();
?> |