Example - Quick -- Quickly bind a database record set
ïÐÉÓÁÎÉÅ
Binding a result set
To begin binding an existing record set of data to a DataGrid you can
easy use the
bind()
method.
Пример 53-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');
$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();
?> |
|