Title: ReportList Class Marked Cool (Review this resource) Author: dclark13 Posted On: 2004-12-01 Category: Home > PHP Classes
Popularity:
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: 2147 Total Votes: 6
Total Points: 23 (6 reviews) [ Download ]
Example 4 - Pagination of Results
You want to paginate your results so that only a few records show on the page at a time. This can be
accomplished with only two extra method calls, assuming you want to use standard $_GET parameters:
one to set the pagination target (using allowPaging) and a second to set what record
to start outputting data for and how many records to show per page (using setListRange).
$oList->allowPaging(true, $_SERVER['PHP_SELF'] . '?Base=');
$oList->setListRange($_GET['Base'], 2);
This will output the following table (feel free to try out the pagination links):
Customer Search Results "Amount paid" figures are as of quarter-end. Record(s) 1 to 2 of 5 total.
| << Prev | Back | 1 | 2 | 3 | More | Next >> |
| First Name | Last Name | Home Phone | State | Amount Paid |
| David | Clark | (801) 254-1691 | UT | $123.45 |
| Valerie | Smith | (801) 974-6721 | IN | $4,914.23 |
Example 5 - Sorting of Results
You want to allow sorting by any of the columns in your output list, just by clicking on the column header.
To do this, you must specify how the data is currently sorted (by what field, and whether or not it is sorted
in descending order) and what page should serve as the target to perform the sort (usually just the current
page). Two things to note are that the ReportList class will usually sort data properly depending on it's
datatype (PHP is not strongly typed, but it is type-aware), and that the normal pagination handling will work
in conjunction with the sorting to provide consistent results.
$oList->allowSort(true, $_GET['Sort'], $_GET['SortDescending'],
'reportlist_example.php');
This will output the following table (feel free to try out the sorting links, and be sure to hover over them with
your mouse for a moment to read the descriptions):
Example 6 - Linking by Records
You want each piece of data in the HTML table to be a hyperlink to some other page, possibly with
more information about that particular record. This is useful in reporting systems where you want users
to be able to drill-down to different levels of detail. You can configure the ReportList class to output static
links, or links that are built using data for each individual record as parameters: to accomplish the latter,
you must specify the link target page and an array of parameters that you want to use in the link (each
parameter must detail the exact data field name and the URL parameter name to use); to accomplish the
static links, simply omit the array of parameter information.
$oList->allowLink(true, 'reportlist_example.php',
array(
array('name'=>'strHomePhone', 'marker'=>'HP'),
array('name'=>'strState', 'marker'=>'ST')
)
);
This will output the following table:
Example 7 - Adding a Touch of Style
Let's say you're not satisfied with the default appearance of the HTML table that the ReportList generates. Certainly
a possibility since there's very little formatting applied automatically. Not to fear though, you're not out of luck. The
ReportList class provides mechanisms to customize the appearance of all of the following aspects: the overall table,
the title, subtitle, recordcount/caption, page navigator row, column heading row, odd & even rows, active rows (i.e.
using the mouseover() event) and record links. For instance, if you define the following style classes:
<style>
.resultsMain { background: #cccccc; border: 1px black solid; }
.resultsCaption { background: #cccccc; border: 1px black solid;
text-align: left; }
.resultsPaging { background: #999999; font-family: sans-serif; }
.resultsHeading { background: #999999; font-family: sans-serif; }
.resultsRowOdd { background: #cccccc; }
.resultsRowEven { background: #ffffff; }
.resultsRowHover { background: #9999cc; }
.resultsTitle { font-size: 125%; font-weight: 600; }
.resultsSubTitle { font-style: italic; }
</style>
You can use the following code to call each class:
$oList->setMainAttributes('class="resultsMain"');
$oList->setTitle('Customer Search Results', '<font class="resultsTitle">',
'</font>');
$oList->setSubTitle('"Amount paid" figures are as of quarter-end.',
'<font class="resultsSubTitle">', '</font>');
$oList->setCaptionAttributes('class="resultsCaption"');
$oList->setPageNavigatorAttributes('class="resultsPaging"');
$oList->setFieldHeadingAttributes('class="resultsHeading"');
$oList->setRowAttributes('class="resultsRowOdd"',
'class="resultsRowEven"', 'resultsRowHover');
Notice that for title & subtitle attributes you must specify both open and closing tags, and for the hover row
attributes (the third parameter to the setRowAttributes method) you can specify only a class name - no
other attribute specifications will work correctly for the hover mechanism.
The above code will output the following table:
Customer Search Results "Amount paid" figures are as of quarter-end. Record(s) 1 to 2 of 5 total.
| << Prev | Back | 1 | 2 | 3 | More | Next >> |
| First Name | Last Name | Home Phone | State | Amount Paid |
| David | Clark | (801) 254-1691 | UT | $123.45 | | Valerie | Smith | (801) 974-6721 | IN | $4,914.23 |
|