KoolReport's Forum

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

Joining Two Tables Throws an exception #471

Open Charlie opened this topic on on Sep 18, 2018 - 7 comments

Charlie commented on Sep 18, 2018

When I try and run the code below I get the following error:

Error...

18-Sep-2018 14:18:44 UTC] PHP Fatal error: Uncaught Error: Call to undefined method CheckoutList::dataSource() in /Applications/MAMP/bin/phpMyAdmin/examples/MyExamples/AutolibCloudFullSystem/librarian/Reports/CheckoutList/checkoutList.php:29 Stack trace: #0 /Applications/MAMP/bin/phpMyAdmin/examples/MyExamples/AutolibCloudFullSystem/librarian/Reports/koolreport/KoolReport.php(39): CheckoutList->setup() #1 /Applications/MAMP/bin/phpMyAdmin/examples/MyExamples/AutolibCloudFullSystem/librarian/reports/checkoutlist/index.php(3): koolreport\KoolReport->__construct() #2 {main} thrown in /Applications/MAMP/bin/phpMyAdmin/examples/MyExamples/AutolibCloudFullSystem/librarian/Reports/CheckoutList/checkoutList.php on line 29

This is line 29 causing the error: $join->pipe($this->dataSource("together"));

//Code... //***

require_once "../koolreport/autoload.php"; use \koolreport\processes\Join; class CheckoutList extends \koolreport\KoolReport {

function settings()
{
    return array(
        "dataSources"=>array(
            "mydata"=>array(
                'connectionString' => 'mysql:host=localhost;dbname=MYSQL..........',
                'username' => 'root',
                'password' => 'root',
                'charset' => 'utf8',
            )
        )
    );
}
function setup()
{
  //  $this->src("mydata")
   // ->query("select * from eloans")
  // ->pipe($this->dataStore("eloans"));
   
    $people_source = $this->src("mydata")->query("select BORRONUM,LastName,FirstName from people");
    $eloans_source = $this->src("mydata")->query("select borroid,bookid,loandate from eloans");
   
    $join = new Join($people_source,$eloans_source,array("BORRONUM"=>"borroid"));
    $join->pipe($this->dataSource("together"));
     
    
    
    
}

}

/* reference

public function setup()

{
    $user_source = $this->src('user_source')->query("select id,name from users");
    $purchase_source = $this->src('purchase_source')->query("select user_id,item,amount from purchases");
    //Note that: user_source and purchase_source can be from different database
    $join = new Join($user_source,$purchase_source,array("id"=>"user_id"));
    $join->pipe($this->dataSource('together'));
}

*/

KoolReport commented on Sep 19, 2018

Hi,

it should be:

$join->pipe($this->dataStore("together"));

It is the dataStore() function, not the dataSource() in your source. The idea is that data after processed is pipe to a store before it is used to render in the view.

Charlie commented on Sep 19, 2018

Thank you for the reply. The documentation for the JOIN needs to be corrected because it shows dataSource() : https://www.koolreport.com/data-processing#row-join

KoolReport commented on Sep 19, 2018

That's bad! We have fixed it. Thank you for letting us know.

Charlie commented on Sep 19, 2018

I want to take my example a step further with an INNER and LEFT JOIN.

The SQL below I am trying to get to work with KoolReports.

*SELECT Mbook.BOOKNUM,
  Mbook.TITLE,
  Eloans.bookid,
  Eloans.loandate,
  Eloans.borroid,
  people.Borronum,
  people.FirstName,
  people.LastName
FROM(
    Mbook
    INNER JOIN Eloans ON Mbook.BOOKNUM = Eloans.bookid
    LEFT JOIN people ON Eloans.borroid = people.Borronum
  )*

This is what I have so far but do not know how to proceed.

    $borro_source = $this->src('mydata')->query("select Borronum,LastName,FirstName from people");
    $eloans_source = $this->src('mydata')->query("select borroid,bookid,loandate from Eloans");
    $mbook_source = $this->src('mydata')->query("select BOOKNUM,TITLE from Mbook");
    $join = new Join($borro_source,$eloans_source,$mbook_source,array("Borronum"=>"borroid" and ("BOOKNUM"=>"bookid")); 
    $join->pipe($this->dataStore("checkouts"));
Keith Burke commented on Sep 20, 2018

Outsider looking in....

Why not just use your sql statement as your data source? My understanding of koolReports doing joins, grous and sorts etc is that is makes handling other data sources much easier [text files etc]

Also, you are downloading massive amounts of data to the webpage THEN joining THEN displaying a subset of data. Much less resource hungry to have your MySQL perform all that stuff on server then download just the data you want to the koolReport controller.

KoolReport commented on Sep 20, 2018

We totally agree with Keith Burke. PHP in general and KoolReport in particular could not compete with DB system in the efficiency to handle data tasks like joining table. So use Join process of KoolReport when:

  1. Your data comes from CSV, Excel or any sources of data which does not have join capability.
  2. You want to join 2 tables from different databases.

In other cases, try to let databases handle data general tasks like Join, Filter, Group if possible. By this way your report will run faster and reduce the amount of network data transfer.

Charlie commented on Sep 20, 2018

Thank you both for your feedback.

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
help needed

None