An Extensive Examination of the PHP:DataGrid Component: Part 1
By Dennis Pallett2005-09-14
Binding Data
Binding data to a datagrid is really easy, and requires only one line of real PHP code. The PHP:DataGrid component automatically creates a variables called $_DATAGRID (not a superglobal, unfortunately). To bind data, you have to call the bind() method on the $_DATAGRID variable, like so:
$_DATAGRID->bind('test', $data);
That's all! The test datagrid will now be shown, with the data contained in the $data variable. The $data variable must be an array that was retrieved using mysql_fetch_array() and a loop (see the datagrid example below if you're unsure about this) or similar format. In any case, it should look like this:
Array ( [0] => Array ( [id] => 1 [title] => Item 1 [category] => 4 )
[1] => Array ( [id] => 2 [title] => Item 2 [category] => 7 )
[2] => Array ( [id] => 3 [title] => Item 3 [category] => 3 ) )
The above is a valid $data array. It won't accept any other format, and an error will be shown if you do bind a different format.
Tutorial Pages:
» Introduction
» What is PHP:DataGrid?
» The Basics
» Binding Data
» An Example
» Summary
