KoolReport's Forum

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

How can variables be used in queries? #1583

Closed The O opened this topic on on Aug 19, 2020 - 1 comments

The O commented on Aug 19, 2020

Some values will only be known at run-time. Is it possible to use variables as query parameters in KoolReports? For example, in this example, how can I replace the raw value with a variable viz:

$val = 1.0825;
DB::table('orders')->selectRaw('price * ? as price_with_tax', [$val])

Or here,

<?php
use \koolreport\processes\Filter;
$val = 50;

class MyReport extends \koolreport\KoolReport
{
    public function setup()
    {
        ...
        ->pipe(new Filter(array(
            array("region","=","asia"),
            array("customerAge",">",$val)
        )))
        ...
    }
}

This doesn't seem to be possible and causing the challenge I have here. Or is there some other way to achieve this generally with the package?

Beginning to feel buyer's remorse...

David Winterburn commented on Aug 20, 2020

Your so called run time values (variables) to be used with query are called report's inputs. Please check a classic example of it:

https://www.koolreport.com/examples/reports/inputs/order_list/

When users change an input value, the change is posted back for the report to catch it and change the report's content accordingly. Let us know if you meant something else. Thanks!

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
solved

None