I have multiple tables that have similar data that I'm trying to use a Multi Select filter with. When I put the params in both WHERE statements, I'm getting a "SQLSTATE[HY093]: Invalid parameter number" error. If I take out the second query, everything works fine. I don't want to make it a subquery, because the tables are very large (3M+) and the query results are also very big (100k+ rows) and the performance would suffer. I know it has to do with the params, but I'm still trying to understand how they work, so any help would be appreciated.
For security reasons, I've simplified the code and changed the fields. Here's the view.php
<?php
    use \koolreport\datagrid\DataTables;
    use \koolreport\inputs\Select2;
?>
<html>
    <div style="margin:30px;">
    <head>
    <title>Example</title>
    </head>
    <body>
        <h1>Example</h1>
        <form method="get">
        <div class="row"> 
            <div class="col-sm-1">
            From Quarter:
                <?php
                Select2::create(array(
                    "name"=>"startQtrPicker",
                    "dataStore"=>$this->dataStore("yearQtr"),
                    "attributes"=>array(
                        "class"=>"form-control"),
                    ));
                ?>
            </div>   
            <div class="col-sm-1">
            To Quarter:
                <?php
                Select2::create(array(
                    "name"=>"endQtrPicker",
                    "dataStore"=>$this->dataStore("yearQtr"),
                    "attributes"=>array(
                        "class"=>"form-control"),
                    ));
                ?>
            </div>
            <div class="col-sm-2">
            Name:
                <?php
                Select2::create(array(
                    "name"=>"namePicker",
                    "multiple"=>true,
                    "dataStore"=>$this->dataStore("name"),
                    "dataBind"=>array(
                        "text"=>"Title",
                        "value"=>"__kp_Name_ID"),
                    "attributes"=>array(
                        "class"=>"form-control"),
                    ));
                ?>
            </div>
            <div class="col-sm-2">
            Location:
                <?php
                Select2::create(array(
                    "name"=>"location",
                    "multiple"=>true,
                    "dataStore"=>$this->dataStore("location"),
                    "dataBind"=>array(
                        "text"=>"Location",
                        "value"=>"__kp_Location_ID"),
                    "attributes"=>array(
                        "class"=>"form-control"),
                    ));
                ?>
            </div>
          </div>         
            <div class="form-group" style="margin-top:22px;">
            <button class="btn btn-md btn-primary">Search</button>
            </div>
        </form>
        </div>
        </div>
        <?php
        DataTables::create(array(
            'name' => 'Example',
            "cssClass"=>array(
                "table"=>"table table-striped table-bordered"),
            'dataSource' => function() {
                return $this->src('mysql2')
                ->query('
                #TABLE1           
                SELECT 
                StatementYearQuarter AS "Statement_YrQtr",
                Names.Title AS "Standard_Name",
                Locations.Name AS "Location",
                FROM (TABLE1
                LEFT JOIN Names ON Names.__kp_Name_ID=TABLE1._kf_Name_ID
                LEFT JOIN Locations ON Locations.__kp_Location_ID=TABLE1._kf_Location_ID
                )
                WHERE 1=1
                '.(($this->params["startQtrPicker"]!=array())?"and TABLE1.StatementYearQuarter BETWEEN :startQtrPicker AND :endQtrPicker":"").'
                '.(($this->params["namePicker"]!=array())?"and TABLE1._kf_Name_ID in (:namePicker)":"").'
                '.(($this->params["locationPicker"]!=array())?"and TABLE1._kf_Location_ID in (:locationPicker)":"").'
                UNION ALL
                #TABLE2
                SELECT
                StatementYearQuarter AS "Statement_YrQtr",
                Names.Title AS "Standard_Name",
                Locations.Name AS "Location",
                FROM (TABLE2
                LEFT JOIN Names ON Names.__kp_Name_ID=TABLE2._kf_Name_ID
                LEFT JOIN Locations ON Locations.__kp_Location_ID=TABLE2._kf_Location_ID
                )
                WHERE 1=1
                '.(($this->params["startQtrPicker"]!=array())?"and TABLE2.StatementYearQuarter BETWEEN :startQtrPicker AND :endQtrPicker":"").'
                '.(($this->params["namePicker"]!=array())?"and TABLE2._kf_Name_ID in (:namePicker)":"").'
                '.(($this->params["locationPicker"]!=array())?"and TABLE2._kf_Location_ID in (:locationPicker)":"").'
                
                ')
                ->params(array(
                    ":startQtrPicker"=>$this->params["startQtrPicker"],
                    ":endQtrPicker"=>$this->params["endQtrPicker"],
                    ":namePicker"=>$this->params["namePicker"],
                    ":locationPicker"=>$this->params["locationPicker"],
                ));
            },
            "options" => array(
                "searching" => true,
                "paging" => true,
                "colReorder" => true,
                "order"=>array(
                    array(0,"asc")),
                "pageLength" => 25, 
                ),
            "serverSide"=> true,
        ));
        ?>
    </body>
</html>