Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100 off


PHP Tutorials and Scripts   




Title: ReportList Class    Marked Cool    (Review this resource)
Author: dclark13
Posted On: 2004-12-01
Category: Home > PHP Classes

Popularity: 1 points out of 10    

Description: Quickly output data arrays, especially query results. Features record linking (i.e. drill-down support), pagination, column sorting, row highlighting, and downloading to delimited text files and XML.

Total Hits: 2076     Total Votes: 6     Total Points: 23 (6 reviews)        [ Download ]   

Page Navigation:  [1]  [2]  [3]


ReportList - Example Usage
April 2004



Purpose
The ReportList class was originally designed as the foundation to an online reporting system for a database-driven website. It was hoped that it could be used to greatly simplify the migration of a set of database query results to an HTML page, with full user navigation control and export options that would allow power users to analyze data offline, in programs like Excel or OpenOffice Calc. Over the course of several years now the class has lived up to these expectations in numerous projects and has grown to support many more features than I originally imagined. Below is a brief example of some of the more common methods and usages of the ReportList class.

Preface
For the following examples, assume that the $arrData array is set up as the following (more likely your array will have been populated by a database query, but the format will be similar):


$arrData = array();
array_push($arrData, array('strFName'=>'David', 'strLName'=>'Clark', 
  'strHomePhone'=>'8012541691', 'strState'=>'ut', 'curAmountPaid'=>123.45));
array_push($arrData, array('strFName'=>'Valerie', 'strLName'=>'Smith',
  'strHomePhone'=>'8019746721', 'strState'=>'in', 'curAmountPaid'=>4914.23));
array_push($arrData, array('strFName'=>'Thomas', 'strLName'=>'Edison',
  'strHomePhone'=>'5191220', 'strState'=>'ut', 'curAmountPaid'=>45.78));
array_push($arrData, array('strFName'=>'Marie', 'strLName'=>'Curie',
  'strHomePhone'=>'8238485', 'strState'=>'ct', 'curAmountPaid'=>798));
array_push($arrData, array('strFName'=>'Isaac', 'strLName'=>'Asimov',
  'strHomePhone'=>'8609784612', 'strState'=>'ct', 'curAmountPaid'=>1540.1));

Example 1 - Instantiation & Output
You have an array of data ($arrData) that you want to output as quickly and easily as possible in a standard HTML table.


require_once('ReportList.php');
$oList = new ReportList();
$oList->makeListFromArray($arrData);

This will output the following table:

Record(s) 1 to 5 of 5 total.
strFNamestrLNamestrHomePhonestrStatecurAmountPaid
DavidClark8012541691ut123.45
ValerieSmith8019746721in4914.23
ThomasEdison5191220ut45.78
MarieCurie8238485ct798
IsaacAsimov8609784612ct1540.1

 

Example 2 - Specifying Headings
You need to output the HTML table for the $arrData array, but you want to add some title/sub-title information. You'd also like to rename the columns so that they are more appropriate for display - to do this, you must manually specify each column that you want to show. [As before, you must still call the makeListFromArray function to actually output any HTML.]


$oList->setTitle('Customer Search Results');
$oList->setSubTitle('"Amount paid" figures are as of quarter-end.');
$oList->addOutputColumn('strFName', 'First Name');
$oList->addOutputColumn('strLName', 'Last Name');
$oList->addOutputColumn('strHomePhone', 'Home Phone');
$oList->addOutputColumn('strState', 'State');
$oList->addOutputColumn('curAmountPaid', 'Amount Paid');

This will output the following table:

Customer Search Results
"Amount paid" figures are as of quarter-end.
Record(s) 1 to 5 of 5 total.
First NameLast NameHome PhoneStateAmount Paid
DavidClark8012541691ut123.45
ValerieSmith8019746721in4914.23
ThomasEdison5191220ut45.78
MarieCurie8238485ct798
IsaacAsimov8609784612ct1540.1

 

Example 3 - Formatting Data
In our examples so far the "Home Phone" and "Amount Paid" data isn't formatted at all. It would be nice to show these properly as phone numbers, and (U.S.) currency figures. Also, states are normally all upper-case. To do so, modify the calls to the addOutputColumn method to specify data formats for each of these fields. While we're doing that we might as well right-justify the "State" and "Amount Paid" column, since that is more typical of those data formats than left-alignment.


$oList->addOutputColumn('strHomePhone', 'Home Phone', 'phone');
$oList->addOutputColumn('strState', 'State', 'ucase', 'right');
$oList->addOutputColumn('curAmountPaid', 'Amount Paid', 'dollars',
                      'right');

This will output the following table:

Customer Search Results
"Amount paid" figures are as of quarter-end.
Record(s) 1 to 5 of 5 total.
First NameLast NameHome PhoneStateAmount Paid
DavidClark(801) 254-1691UT$123.45
ValerieSmith(801) 974-6721IN$4,914.23
ThomasEdison519-1220UT$45.78
MarieCurie823-8485CT$798.00
IsaacAsimov(860) 978-4612CT$1,540.10

 


Page Navigation:  [1]  [2]  [3]



© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.