Join

This example shows the usage of Join method

First Table
first_idname
1 John
2 Marry
3 Peter
4 Donald
Second Table
second_idincome
1 $50,000
2 $60,000
3 $100,000
4 $80,000

$join = $this->dataStore("first")->join($this->dataStore("second"),array("first_id"=>"second_id"));
first_idnamesecond_idincome
1 John 1 $50,000
2 Marry 2 $60,000
3 Peter 3 $100,000
4 Donald 4 $80,000

The join() method of DataStore can help to datastore to join with another on matching keys and produce a new datastore which is join of this two datastores.

<?php
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../../koolreport/autoload.php";

use \koolreport\processes\ColumnMeta;
use \koolreport\processes\Filter;

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            "dataSources"=>array(
                "first"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table",
                    "data"=>array(
                        array("first_id","name"),
                        array(1,"John"),
                        array(2,"Marry"),
                        array(3,"Peter"),
                        array(4,"Donald"),
                    )
                ),
                "second"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table",
                    "data"=>array(
                        array("second_id","income"),
                        array(1,50000),
                        array(2,60000),
                        array(3,100000),
                        array(4,80000),
                    )
                ),
            )
        );
    }
    protected function setup()
    {
        //Prepare data

        $this->src("first")
        ->pipe($this->dataStore("first"));

        $this->src("second")
        ->pipe(new ColumnMeta(array(
            "income"=>array(
                "type"=>"number",
                "prefix"=>"$"
            )
        )))
        ->pipe($this->dataStore("second"));

    }
}
<?php
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\LineChart;
?>
<div class="report-content">
    <div class="text-center">
        <h1>Join</h1>
        <p class="lead">This example shows the usage of Join method</p>
    </div>
    
    <div class="row">
        <div class="col-md-6">
            <h5 class="text-center">First Table</h5>
            <?php
            Table::create(array(
                "dataSource"=>$this->dataStore("first"),
                "cssClass"=>array(
                    "table"=>"table-bordered table-striped table-hover"
                )
            ));
            ?>        
        </div>
        <div class="col-md-6">
            <h5 class="text-center">Second Table</h5>
            <?php
            Table::create(array(
                "dataSource"=>$this->dataStore("second"),
                "cssClass"=>array(
                    "table"=>"table-bordered table-striped table-hover"
                )
            ));
            ?>        
        </div>
    </div>


<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
$join = $this->dataStore("first")->join($this->dataStore("second"),array("first_id"=>"second_id"));
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>
    <div style="margin-top:20px;">
    <?php
    $join = $this->dataStore("first")->join($this->dataStore("second"),array("first_id"=>"second_id"));
    Table::create(array(
        "dataSource"=>$join,
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>
    </div>

</div>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport