KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Opening a second "src" in the same report #1517

Open Richb201 opened this topic on on Jul 8, 2020 - 1 comments

Richb201 commented on Jul 8, 2020

Below is my setup of my initial table in MyReport

   function setup()
    {
        $this->src('substantiator')
            ->query("SELECT bus_comp FROM business_components WHERE campaign='Apple' AND email='richb201@gmail.com'")
            ->pipe(new ColumnRename(array(
            "bus_comp"=>"Business Component")))
            ->pipe($this->dataStore("business_components"));
    }

and in MyReports.view I have

Table::create(array(
    "dataStore"=>$this->dataStore("business_components"),
    "class"=>array(
        "table"=>"table table-hover"
    )
));

This generates works fine.

Next, on the same report, further down the report, I want to use a different table completely. For example

        $this->src('substantiator')
            ->query("SELECT name FROM employees WHERE campaign='Apple' AND email='richb201@gmail.com'")
            ->pipe(new ColumnRename(array(
            "name"=>"employee name")))
            ->pipe($this->dataStore("employees"));

How do I do this? Do you have any example of using two different table on a single report , not with a join?

A different question:

In the above examples I hard coded in the 'campaign' and the 'email'. In reality I need to use this:

$this->src('substantiator')
            ->query("SELECT bus_comp FROM business_components WHERE campaign=$this->$_SESSION['campaign'] AND email='richb201@gmail.com'")

But I get an error:

Message: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

Please tell me how to use a session variable in the query.

KoolReport commented on Jul 9, 2020

For your questions:

  1. No problem with that, you can create another table like this:
<h3>First Table</h3>
<?php
Table::create(array(
    "dataStore"=>$this->dataStore("business_components"),
    "class"=>array(
        "table"=>"table table-hover"
    )
));
?>
<h3>Second Table</h3>
<?php
Table::create(array(
    "dataStore"=>$this->dataStore("employees"),
    "class"=>array(
        "table"=>"table table-hover"
    )
));
?>
  1. Do this
$this->src('substantiator')
            ->query("SELECT bus_comp FROM business_components WHERE campaign='".$_SESSION['campaign']."' AND email='richb201@gmail.com'")

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None