PHP Classes

File: Examples.txt

Recommend this page to a friend!
  Classes of verni  >  PHP Report  >  Examples.txt  >  Download  
File: Examples.txt
Role: Documentation
Content type: text/plain
Description: Some examples
Class: PHP Report
Generate Excel, HTML, PDF reports from data arrays
Author: By
Last change: Changed file extension
Date: 10 years ago
Size: 5,380 bytes
 

Contents

Class file image Download
## 1. The simplest example, just some array of data <pre> include '../PHPReport.php'; $R=new PHPReport(); $R->load(array( 'id'=>'product', 'data'=>array( array('Some product',23.99,12), array('Other product',5.25,2.25), array('Third product',0.20,3.5) ) ) ); echo $R->render(); exit(); </pre> ## 2. We can format some data, like prices <pre> $R=new PHPReport(); $R->load(array( 'id'=>'product', 'data'=>array( array('Some product',23.99,12), array('Other product',5.25,2.25), array('Third product',0.20,3.5) ), 'format'=>array( 1=>array('number'=>array('prefix'=>'$','decimals'=>2)), 2=>array('number'=>array('sufix'=>' EUR','decimals'=>1)) ) ) ); echo $R->render(); </pre> ## 3. Add header and footer row <pre> $R=new PHPReport(); $R->load(array( 'id'=>'product', 'header'=>array( 'Product name','Price','Tax' ), 'footer'=>array( '',28.54,17.89 ), 'data'=>array( array('Some product',23.99,12), array('Other product',5.25,2.25), array('Third product',0.20,3.5) ), 'format'=>array( 1=>array('number'=>array('prefix'=>'$','decimals'=>2)), 2=>array('number'=>array('sufix'=>' EUR','decimals'=>1)) ) ) ); echo $R->render('excel'); </pre> ## 4. It's possible to set some attributes to columns, like width or alignment <pre> $R=new PHPReport(); $R->load(array( 'id'=>'product', 'header'=>array( 'Product name','Price','Tax' ), 'footer'=>array( '',28.54,17.89 ), 'config'=>array( 0=>array('width'=>120,'align'=>'left'), 1=>array('width'=>80,'align'=>'right'), 2=>array('width'=>80,'align'=>'right') ), 'data'=>array( array('Some product',23.99,12), array('Other product',5.25,2.25), array('Third product',0.20,3.5) ), 'format'=>array( 1=>array('number'=>array('prefix'=>'$','decimals'=>2)), 2=>array('number'=>array('sufix'=>' EUR','decimals'=>1)) ) ) ); echo $R->render('excel'); </pre> ## 5. We can use named columns (associative arrays) and set attribute for header and footer separately <pre> $R=new PHPReport(); $R->load(array( 'id'=>'product', 'header'=>array( 'product'=>'Product name','price'=>'Price','tax'=>'Tax' ), 'footer'=>array( 'product'=>'','price'=>28.54,'tax'=>17.89 ), 'config'=>array( 'header'=>array( 'product'=>array('width'=>120,'align'=>'center'), 'price'=>array('width'=>80,'align'=>'center'), 'tax'=>array('width'=>80,'align'=>'center') ), 'data'=>array( 'product'=>array('align'=>'left'), 'price'=>array('align'=>'right'), 'tax'=>array('align'=>'right') ), 'footer'=>array( 'price'=>array('align'=>'right'), 'tax'=>array('align'=>'right') ) ), 'data'=>array( array('product'=>'Some product','price'=>23.99,'tax'=>12), array('product'=>'Other product','price'=>5.25,'tax'=>2.25), array('product'=>'Third product','price'=>0.20,'tax'=>3.5) ), 'format'=>array( 'price'=>array('number'=>array('prefix'=>'$','decimals'=>2)), 'tax'=>array('number'=>array('sufix'=>' EUR','decimals'=>1)) ) ) ); echo $R->render(); </pre> ## 6. Grouping data is also possible <pre> $R=new PHPReport(); $R->load(array( 'id'=>'product', 'header'=>array( 'product'=>'Product name','price'=>'Price','tax'=>'Tax' ), 'footer'=>array( 'product'=>'','price'=>28.54,'tax'=>17.89 ), 'config'=>array( 'header'=>array( 'product'=>array('width'=>120,'align'=>'center'), 'price'=>array('width'=>80,'align'=>'center'), 'tax'=>array('width'=>80,'align'=>'center') ), 'data'=>array( 'product'=>array('align'=>'left'), 'price'=>array('align'=>'right'), 'tax'=>array('align'=>'right') ), 'footer'=>array( 'price'=>array('align'=>'right'), 'tax'=>array('align'=>'right') ) ), 'data'=>array( array('product'=>'Some product','price'=>23.99,'tax'=>12), array('product'=>'Other product','price'=>5.25,'tax'=>2.25), array('product'=>'Third product','price'=>0.20,'tax'=>3.5) ), 'group'=>array( 'caption'=>array( 'Category 1', 'Another category' ), 'rows'=>array( array(0), array(1,2) ), 'summary'=>array( array('product'=>'','price'=>23.99,'tax'=>12), array('product'=>'','price'=>5.45,'tax'=>5.75) ) ), 'format'=>array( 'price'=>array('number'=>array('prefix'=>'$','decimals'=>2)), 'tax'=>array('number'=>array('sufix'=>' EUR','decimals'=>1)) ) ) ); echo $R->render('excel'); </pre> View more advanced examples with templates http://github.com/vernes/PHPReport/wiki/Examples-with-templates