---
title: "Displaying Data into PHP DataGrid"  
description: "The basic PHP datagrid requires only as little as two lines of code. Fore mostly, always create PHPGrid object in the first line; then call its method"  
author: "Anonymous User"  
published: 2011-12-17  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/276/displaying-data-into-php-datagrid  
category: "php"  
tags: ["php"]  
reading_time: 2 minutes  

---

# Displaying Data into PHP DataGrid

The basic PHP datagrid requires only as little as two lines of code. Fore mostly, always create PHPGrid object in the first line; then call its methods to define [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties), and lastly always call display() to render to screen.\

Please note in some databases, such as Firebird, [MS Access](https://www.mindstick.com/blog/477/shortcut-keys-for-formatting-elements-in-pivottable-view-for-ms-access), the fields name are case-sensitive. Make sure the name used in the code matches the case when you are using those types of databases.

Syntax:

```
C_DataGrid($sql_Query, $sql_key, $sql_TableName, $db_Connection);
```

Where:

$sql_Query -> it is a required parameter which represents the [SQL Query](https://www.mindstick.com/forum/529/rename-table-name-and-column-name-using-sql-query) to select data from the table. generally [select query](https://www.mindstick.com/articles/1858/sqlite-select-query) is used.

$sql_Key -> it is a required parameter which represents the [primary key](https://www.mindstick.com/blog/214/primary-key) of [database table](https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table).By default it takes ‘id‘ field of database table.

$sql_TableName -> it is also a required parameter which represents the desired database table’s form where you want have to select data.

$db_Connection -> it is an [optional parameter](https://www.mindstick.com/interview/1310/how-do-i-simulate-optional-parameters-to-com-calls) which allows datagrid to reference to a [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) [data source](https://www.mindstick.com/interview/808/what-is-a-data-source) on the fly.

**Example**: Select [data from the database](https://www.mindstick.com/forum/160510/how-to-fetch-data-from-the-database-in-the-dot-net-console-application-using-c-sharp) table and displaying into the PHP datagrid.

```
<?php  // connect with database           mysql_connect("localhost", "root", "root");// select database name        mysql_select_db("tempdatabase");  // select value from database table        $dg = new C_DataGrid("SELECT * FROM tempdatabase.tbltemp", "id", "tbltemp");// change column titles        $dg -> set_col_title("id", "ID");        $dg -> set_col_title("Username", "User Name");        $dg -> set_col_title("EmailId", "Email ID");        $dg -> set_col_title("Address", "Permanent Address");        $dg -> set_col_title("MobileNo", "User Mobile No");  // Display data into screen        $dg -> display();

     ?>
```

---

Original Source: https://www.mindstick.com/blog/276/displaying-data-into-php-datagrid

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
