PHP examples

Do not run this file locally
Run it from your (local) web server where is installed your http server like IIS or Apache and PHP 4.x/5.x.

The PHP CGI or ISAPI service program must have write access to all files in folder /Examples/Php/Database
To permit write access on Windows XP right click to file Database in My Computer, select Properties -> Security -> Users and set Full control to Allow. If you don't have Security item in Properties, run My Computer, in menu select Tools - > Folder options -> View and uncheck Use simple file sharing option.

All the examples use SQL database in text files (PHP Text DB). The PHP core files for txt database are located in /php-txt-db-api directory. The database is located in directory /Database where are stored tables as individual txt files.
For database access are used objects Database and Recordset defined in /Framework/IncDbTxt.php file. You can change database provider to other (odbc,ado,sqlite) by including other IncDb...php file and changing connection string when creating Database object.

To test MySQL database run the /Examples/Php/MySqlUTF8.sql script in your MySql database engine.
MySQL must be in UTF8 encoding to store the characters correctly!
The SQL script can be run on database by: mysql.exe -uroot -p < MySqlUTF8.sql
Update paths or copy MySqlUTF8.sql to the MySQL /bin directory a run it here.
To use MySQL database in the PHP examples, modify the php example (e.g. Basic.php), the Database switching paragraph by:
require_once("../Framework/IncDbMySQL.php"); $db = new Database("TreeGridTest","root","your root password");


Example index

Basic AJAX
Basic usage of asynchronous background (new style) communication with server and SQL database communication
Basic AJAX The simplest demonstration of using PHP and AJAX link
Using TreeGrid PHP framework How to generate data from and update data to SQL database using prepared TreeGridFramework.php link
Tree in database How to generate tree from and store tree to SQL database table link
TreeGrid API for communication and reloading Using TreeGrid Extended API link
 
Basic <form> Submit
Basic usage of synchronous (old style) communication with server and SQL database communication
Basic Submit The simplest demonstration of using PHP and <form> submit link
Using TreeGrid PHP framework How to generate data from and update data to SQL database using prepared TreeGridFramework.php link
Tree in database How to generate tree from and store tree to SQL database table link
 
Applications
Few more complex applications with TreeGrid upon SQL database and AJAX communication
Grid from database table Demonstrates advanced generating from and updating to database link
Complete application - Schools Complete application to demonstrate generating from and updating to different database tables with various structure link
 
Server paging
Examples of writing server side support scripts for server side paging upon SQL database
Sorting, uploading changes and export Demonstrates sorting feature, saves changes back to database, supports also export to Excel, all upon SQL database link
Grouping Demonstrates grouping with server paging and client child paging - all children from groups are sent to server at once link
Grouping with server child paging Demonstrates grouping with server paging and also server child paging link
 
Server paging with TreeGrid server library
Examples of writing server side support scripts for server side paging with helper library shipped with TreeGrid
DataTable database access Demonstrates using TreeGrid server library upon SQL database link
Complex application upon XML file Shows using TreeGrid server library upon XML file on disk with all supported features, especially grouping link
Sharing and synchronization upon XML file Shows sharing data among more clients and automatic updating client's data after data on server are modified by another client link


Basic AJAX

Basic usage of asynchronous background (new style) communication with server.
Basic demonstration of generating data from and uploading data to SQL database.
All examples are located at "Examples/PHP/BasicAjax/.." directory.
Data are downloaded from or uploaded to server by JavaScript XmlHttpRequest object on background, without reloading/submitting the page content.
You can check from configuration menu option Auto update changes to server for immediate updates after edit/modify.
When debugging, you can set <treegrid ... Debug='3' ... > to see communication with server. It opens two new browser's windows. You can see XML data or PHP error server returned.
Remember, in Ajax communication, the PHP page must return only xml data, not any standard html tags like <html> or <!doctype>.
See documentation
AJAX versus submit and also tutorial Identifying rows when uploading.

Basic AJAX
Main file Basic.html, support code Basic.php
Layout file in DBDef.xml, data in database table "TableData".
The simplest demonstration of using PHP and AJAX. It generates data from database table 1:1 including id. Also updates changes to database according to id.

Using TreeGrid PHP framework
Main file Framework.html, support code Framework.php, framework code /Framework/TreeGridFramework.php
Layout file in DBDef.xml, data in database table "TableData".
The same example as previous one, but with using functions from TreeGrid PHP Framework. It also shows using custom parameters in <treegrid> tag.

Tree in database
Main file TreeFramework.html, support code TreeFramework.php, framework code /Framework/TreeGridFramework.php
Layout file in TreeDef.xml, data in database table "TreeData".
Generates treetable from database table with column Parent where are relations Parents/Children. Parent column contains parent's id of the child. For root rows it contains "#Body", for fixed rows "#Head" or "#Foot".
Uploaded rows are still identified by preset and standardly generated id attributes.
Uses functions from TreeGrid PHP Framework.

TreeGrid API for communication and reloading
Main file API.html, support codes Framework.php and TreeFramework.php, framework code /Framework/TreeGridFramework.php
Layout files in DBDef.xml and TreeDef.xml, data in database tables "TableData" and "TreeData".
It shows two tables from previous examples and demonstrates Extended API functions for reloading, changing data source when reloading, catching data event and so on.


Basic <form> Submit

Basic usage of synchronous (old style) communication with server.
Basic demonstration of generating data from and uploading data to SQL database.
All examples are located at "Examples/PHP/BasicSubmit/.." directory.
Data are included in page in hidden <input>. Changes are sent to server in this hidden <input> of submitted <form> on page.
See documentation
AJAX versus submit and also tutorial Identifying rows when uploading.

Basic Submit
Main file Basic.php
Layout file in DBDef.xml, data in database table "TableData".
The simplest demonstration of using PHP and standard page submit. It generates data from database table 1:1 including id. Also updates changes to database according to id.

Using TreeGrid PHP framework
Main file Framework.html, framework code /Framework/TreeGridFramework.php
Layout file in DBDef.xml, data in database table "TableData".
The same example as previous two, but with using functions from TreeGrid PHP Framework. Also shows using custom parameters.

Tree in database
Main file TreeFramework.php, framework code /Framework/TreeGridFramework.php
Layout file in TreeDef.xml, data in database table "TreeData".
Generates treetable from database table with column Parent where are relations Parents/Children. Parent column contains parent's id of the child. For root rows it contains "#Body", for fixed rows "#Head" or "#Foot".
Uploaded rows are still identified by preset and standardly generated id attributes.
Uses functions from TreeGrid PHP Framework.


Applications

Few more complex applications with TreeGrid upon SQL database and AJAX communication.

Grid from database table
Main file Grid.html, support codes GridLayout.php as layout, GridData.php as data, GridUpload.php as upload
Data are in database table "TableData".
Demonstrates advanced generating from and updating to database.
Generates treetable from standard database table. Also flips the table and shows data in changed layout.
For every action there is used another support code (Layout, Data, Upload). The layout is also generated.
Rows are identified by one unique editable column, with using full ids (including parents ids).
For demonstration it shows id column, to see what ids are generated by TreeGrid.

Complete application - Schools
Main file Schools.html
Support codes Schools.php (main file generates data and also saves changes to database or adds new user),
SchoolsRatings.php (loads reviews for given record, used for server child paging),
SchoolsReview.php (saves one review to database, called as custom AJAX call).
Layout file in SchoolsDef.xml, data in database tables "Schools_Schools", "Schools_Ratings" and "Schools_Users".
Uses also file SchoolsStars.gif ()
Complete application to demonstrate generating from and updating to different database tables with various structure. Demonstrates also server child paging feature (loading children on demand). And also custom AJAX call.
The application show list of schools that can be sorted and filtered. The records can be added/deleted or modified by logged user or admin. The records can be rated and reviewed by visitors.


Server paging

Examples of writing server side support scripts for server side paging upon SQL database.
Demonstration of implementation of various TreeGrid features, like sorting, grouping and export.
All examples use AJAX communication (server side paging cannot be done by synchronous communication).
All examples are located at "Examples/PHP/Paging/.." directory.

Sorting, uploading changes and export to Excel
Main file SortingExport.html
Layout is in static file SortingExport_Layout.xml
Script for generating data (page list) SortingExport_Data.php
Script for uploading changes back to database SortingExport_Upload.php
Script for generating individual page SortingExport_Page.php
Script for exporting data to Excel SortingExport_Export.php
Data are in database table "TableData".
Demonstrates server side paging upon SQL database. Demonstrates sorting feature, saves changes back to database, supports also export to Excel.
The pages are downloaded on demand from server (when the page is visible by scrollbars).
It is simple example with ineffective database access - it loads all table for every page and throws the rest away.
It also simply reloads all body when rows are added or deleted instead of handling changes in pages.

Grouping
Main file Grouping.html
Layout is in static file Grouping_Layout.xml
Script for generating data (page list) Grouping_Data.php
Script for generating individual page Grouping_Page.php
Data are in database table "TableData".
Demonstrates server side paging upon SQL database. Demonstrates grouping feature.
Demonstrates server paging but client child paging - all children from groups are sent to server at once.
This is only simple example with not ideal database access (for every page gets all data)
The pages are downloaded on demand from server (when the page is visible by scrollbars).

Grouping with server child paging
Main file GroupingChild.html
Layout is in static file (the same as in previous example) Grouping_Layout.xml
Script for generating data (page list) (the same as in previous example) Grouping_Data.php
Script for generating individual page and for individual groups GroupingChild_Page.php
Data are in database table "TableData".
Demonstrates server side paging upon SQL database. Demonstrates grouping feature.
Demonstrates server paging with server child paging - group downloads its children only when it is expanded.
This is only simple example with not ideal database access (for every page gets all data)
The pages are downloaded on demand from server (when the page is visible by scrollbars).


Server paging with TreeGrid server library

Examples of writing server side support scripts for server side paging with helper library shipped with TreeGrid.
Demonstration of implementation of various TreeGrid features, like sorting, filtering, grouping and export.
All examples use
TreeGrid server library The library is named TreeGrid.dll for Windows and TreeGrid.so for Linux and is located at /Server/TreeGrid.dll
To run these examples you must copy the library to your PHP extensions directory and add it to extensions in PHP.ini!
This library can be used only in PHP 5.x. For more information see TreeGrid server library and PHP
Some examples stores data in SQL database, some on disk in XML files.
All examples use AJAX communication (server side paging cannot be done by synchronous communication).
All examples are located at "Examples/PHP/PagingDLL/.." directory.

You can compare these example with the examples in previous section (Server paging) how TreeGrid server library simplifies server side paging implementation.

Using SQL database
Main file DB.html, support code DB.php
Layout file in DBDef.xml, data in database table "TableData".
Demonstration of using TreeGrid server library for server side paging upon SQL database.
This example shows all TreeGrid features sorting, filtering, grouping, calculations, uploading changes and export to Excel.

Complex application upon XML file
Main file File.html, support code File.php
Layout file in FileDef.xml, data in file FileData.xml.
Demonstration of using TreeGrid server library for server side paging upon XML file on disk.
This example shows all TreeGrid features sorting, filtering, grouping, calculations, uploading changes and export to Excel.
It demonstrates especially complex grouping feature and cell editing in various groups.
The complete description is in the example itself.

Sharing and synchronization upon XML file
Main file FileSharing.html, support code FileSharing.php
Layout file in FileDef.xml, data in file FileData.xml.
Demonstration of using TreeGrid server library for server side paging upon XML file on disk.
For this example PHP engine must be run as ISAPI filter and not CGI executable
For more information about ISAPI and CGI see TreeGrid server library and PHP
This example shows all TreeGrid features sorting, filtering, grouping, calculations, uploading changes and export to Excel.
Demonstrates sharing data among more clients and automatic updating client's data after data on server are modified by another client.
The complete description is in the example itself.