KoolReport's Forum

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

Variable name for query #2905

Closed tony valentino opened this topic on on Dec 16, 2022 - 2 comments

tony valentino commented on Dec 16, 2022

is it possible to do something like the following:

<?php

require_once "../vendor/autoload.php";

$x = "tblpass5bevent"; 

use \koolreport\KoolReport;
use \koolreport\processes\Filter;
use \koolreport\processes\TimeBucket;
use \koolreport\processes\Group;
use \koolreport\processes\Limit;
//use \koolreport\clients\Bootstrap;

class TestReport extends \koolreport\KoolReport
{
	
	//use \koolreport\clients\Bootstrap;

    public function settings()
    {
        //Get default connection from config.php
        $config = include "../config.php";

        return array(
            "dataSources"=>array(
                "test_report"=>$config["query_source"]
            )
        );
	
    }   
    protected function setup()
    {
		
        $this->src('test_report')
        
		->query("SELECT * FROM $x")

        ->pipe($this->dataStore('test_by_day'));
    } 

	 
};

?>

I want to use this same query on different tables so it would be convenient to be able to use a variable as the table name.

KoolReport commented on Dec 19, 2022

You can use report parameters like this:

$report = new TestReport([
    "table"=>"tblpass5bevent"
]);

Inside the setup(), you do:

        $this->src('test_report')
        
		->query("SELECT * FROM ". $this->params["table"])

        ->pipe($this->dataStore('test_by_day'));
tony valentino commented on Dec 19, 2022

Thanks. Worked perfectly.

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
solved

None