Integrate .jrxml with PHP (With parameter)

From SimIT Wiki

Jump to: navigation, search

* Before you proceed to here you must complete Create First Report (.jrxml) Via IReport.


Assign Proper Parameter Into report1.jrxml

*PHPJasperXML required you to submit at least parameter in order to operate properly.
1. In Netbean, open report1.jrxml.
2. At the left, focus on 'Report Inspector', right click parameters -> Add Parameter.
3. Click parameter1, change Name to 'para1'
4. Change SQL (Refer last tutorial) so that SQL look like 'SELECT * FROM table1 WHERE record_id > $P{para1}'. You can manipulate SQL with whatever method you like but please make sure the syntax to use parameter is $P{<parametername>}.
5. Press OK and Preview the report, try with difference parameter.

  • You can go to iReport official website to study how to manipulate parameter properly.

Integrate report1.jrxml INTO PHP

1. Download PHPJasperXML from [here]
2. Extract content, copy folder 'class' and place it into your project folder.
3. In Netbean, press File -> New File -> PHP File -> Name it as report1.php (Or whatever name you like, make sure put it same folder with report1.jrxml and accessbile by webserver).
4. Replace the content as below,
<?php
include_once('class/fpdf/fpdf.php');
include_once("class/PHPJasperXML.inc");
$para1=$_GET['para1'];
$xml = simplexml_load_file("report1.jrxml");
$PHPJasperXML = new PHPJasperXML();
$PHPJasperXML->arrayParameter=array("para1"=>$para1);
$PHPJasperXML->xml_dismantle($xml);
$PHPJasperXML->transferDBtoArray("localhost","user1","PASS","db1");
$PHPJasperXML->outpage("I");
?>

5. I assume your project store at folder "sample", here we can try to test our report with url: http://localhost/sample/report1.php?para1=1
6. Now you shall see the report working pretty well, change parameter value and see the difference.

Personal tools