PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Atasa Rossios   Data Grid Object   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: An example file
Class: Data Grid Object
Display MySQL query results in HTML tables
Author: By
Last change:
Date: 17 years ago
Size: 4,807 bytes


Class file image Download
 ***** DataGrid Object PHP Class By Atasa Rossios ******

This class is a cuntinuation of a class made by Carlos Miguel Guevara. (
I keep him informed about the changes I do.

I was looking for a Datagrid class similar to Flash Datagrid.
I like the way you can customize it, clean and simple.
From what I have seen here, Carlos Class was near about.
The reason I uploaded, is to play around with some other people, exchenge ideas, and make a real good component.

So the Functionality of this class is, bind a mysql query to a html table.
Here are the Details

1. Description
According to Carlos:
This class can be used to display MySQL database query results in HTML tables.
The class executes a given SQL query and generates an HTML table that displays the query results.
The class can associate a query result column with a given text that is used to display as title of the table as column header.
The class may also generate navigation links to split the query results table listing in multiple pages with a limited number of results per page.

Just Edit the Css file to your taste. I am not going to say somenting else about css

3. Enhancements I have add
a. Reorganize the class, It now validates under E_STRICT
b. Produce clean XHTML code
c. Bind all the information in the html table it self, includig Paging etc
d. Add Javascript Callback functions support [deleteRecord('id','Params')]
e. Add Optional extra query string additions on the links [page.php?id=1&action=delete)]

3. Instalation
Very Simple.
You will have to bind a SQL query against any SQL Table you have, to see the results

4. Contact
I am open to any additions, enhancements, ideas to implement.
So feel free to contact me at

Atasa Nick Rossios

    //*** Include a connection file or just connect to a database ***/
//*** Include the class ***/

// Initialize the Object
$myGrid = new classDatagrid;

//Bind a query-> Parameters (Sql Query, Table Column Id name)
$myGrid->set_query("select Id, nTitle, DATE_FORMAT(nDate, '%d.%m.%Y')as myDate from news", "Id");
// Set a Caption, Table Title
$myGrid->set_title("This is the Table title");

// if you want a pager set the pages per page
//******** Change the Column Names Names from the default Database Column names *********//
$myGrid->set_col_name("DB_Field_Name_1","Custom Column Title 1"); //
$myGrid->set_col_name("DB_Field_Name_2","Custom Column Title 2");

//******** Set a custom Column Type *********//
    //1. Link
    //2. Link with Custom Text, ovewrites the table field value
    //3. Image
    //4. Date(Format e.g. %d.%m.%Y )
$myGrid->set_col_type("Column_Name","LNK","","Custom text to show");
$myGrid->set_col_type("Column_Name","DATE", "Date_Format");

//******** Setup an Extra Column for the callback Links or Javascript Functions *********//
    //The Javascript accepts a. function name, b. Link Title and Alt Text for the Image, c. extra parameters
    //1. Javascript with Image as a link -> Image_Path -> function name -> Link Title -> extra Function Parameter
    //2. Javascript with Text as a link -> Text to show -> function name -> Link Title

    //The Text accepts a. Text to show, b .Link to a page e.g. home.php, c. Link Title, d. Extra query String e.g. action=delete
    //1. Text with Image as a link -> Image_Path -> Link to Page -> Link Title -> extra Query String
    //2. Text with Text as a link -> Text to show -> Link to Page -> Link Title //

$myGrid->set_tool("J_SCRIPT","IMG","imgs/edit.png","delRec","Click to Delete the Record", "param1");
$myGrid->set_tool("J_SCRIPT","TXT","Delete","delRec","Click to Delete the Record");
$myGrid->set_tool("LNK","IMG","imgs/delete.png","index.php","Click to Delete","action=delete");
$myGrid->set_tool("LNK","TXT","delete","index.php","Click to Delete");

//******** Show an Extra Column with Check boxes (Boolean) (Javascript Function Included to Check all at once) *********//

//******** And Finally display the Datagrid *********//