Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

An Extensive Examination of the PHP:DataGrid Component: Part 1

By Dennis Pallett
2005-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


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1