Home > DeveloperSection > Blogs > Displaying Data into PHP DataGrid

Displaying Data into PHP DataGrid


PHP PHP 
Ratings:
3 Comment(s)
 6486  View(s)
Rate this:

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, and lastly always call display() to render to screen.

Please note in some databases, such as Firebird, 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 to select data from the table.               generally select query is used.

$sql_Key ->  it is a required parameter which represents the primary key of 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 which allows datagrid to reference to a difference data source on the fly.

Example: Select data from the database 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();

     ?>


PHP Gridview

By Rohit Kesharwani on   4 years ago
nice blog.

Displaying Data into PHP DataGrid

By Arun Singh on   4 years ago
Thanks Rohit

gridview

By bhavin g on   3 years ago
Fatal error: Class 'C_DataGrid' not found in H:\xampp\htdocs\newgrid.php on line 12
This error is displaying while running above code can you help?

Don't want to miss updates? Please click the below button!

Follow MindStick