KoolReport's Forum

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

Call query from global variable - predefined list of queries #1807

Open MarkoS opened this topic on on Dec 29, 2020 - 2 comments

MarkoS commented on Dec 29, 2020

Hi all,

I am looking for way to call certain query defined in global variable. I want to create list with all used queries and store it in one php fine and than just include file where needed and use as below:


// stored in libraries/my_queries.php
$my_query_list["first_query"] = "SELECT (*) FROM articles";
$my_query_list["second_query"] = "SELECT (*) FROM comments";
// ...
// ...
$my_query_list["other_query"] = "SELECT (*) FROM top_articles";

And than call it as:

include "libraries/my_queries.php"; // include on the top of the MyReport.php file
// setup() section
$this->src('automaker')
->query($my_query_list["second_query"])
->pipe($this->dataStore("my_results"));

Problem is that it does not "see" globally available variables. What should I do to make this work?

KoolReport commented on Dec 30, 2020

Inside the setup() function, you do:

function setup()
{
    include "libraries/my_queries.php";
    $this->src('automaker')    
    ->query($my_query_list["second_query"])
    ->pipe($this->dataStore("my_second_results"));    
}
MarkoS commented on Dec 30, 2020

Thanks for reply, this actually works. I have a lot of reports and have to include same file x times and number of reports. But okey, it works and thanks a lot.

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