KoolReport's Forum

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

Multiselect passing in each selected option as a new argument?!? #306

Open Jeff Baker opened this topic on on Jun 7, 2018 - 5 comments

Jeff Baker commented on Jun 7, 2018

Trying to implement multiselect, but there is one massive issue with it. It passes in a new argument for each item selected. mysql does not support variable parameters.

I EXPECTED it to pass in all selected items in a comma delimited string to a SINGLE variable so I could break it into an array and do WHERE IN array in mysql.

Is this already possible? Am I missing something?

KoolReport commented on Jun 7, 2018

Could you please share some code so I can understand exactly the issue.

Jeff Baker commented on Jun 11, 2018

So I have this multi-select:

<label>Select Opportunity Status</label> <br>
<?php
    MultiSelect::create(array(
        'name'=>"OppStatus",
        "placeholder"=>"Select Opportunity Status",
	"dataStore"=>$this->dataStore("oppStatus"),
	"dataBind"=>array(
	    "text"=>"opportunityStatusDesc",
	    "value"=>"opportunityStatusId",
	),
	"attributes"=>array(
	"size"=>5,
    )
));
?>

When I select multiple values, I get this error: usp_AgenciesWhoPostedOpportunities('1','3','4', '1', '2017-07-01 00:00:00', '2017-07-31 00:00:00');

The proc is expecting these params: usp_AgenciesWhoPostedOpportunities(IN OppStatus char, IN OrgStatus char, IN StartDate, IN EndDate datetime)

In the error, I selected three items from the multi-select. As you can see, it added 1, 3 and 4 to the params list. I expected it to call the proc like this: usp_AgenciesWhoPostedOpportunities('1,3,4', '1', '2017-07-01 00:00:00', '2017-07-31 00:00:00');

Notice how the first param is a list of the IDs

Jeff Baker commented on Jun 11, 2018

I figured out a work-around, but seriously this control should be sending in a string of comma delimited items, not trying to insert them as new params for each item selected. Solution:

":OppStatus"=>implode(",",$this->params["OppStatus"]),
KoolReport commented on Jun 11, 2018

Actually, the way you did is the same way we want to suggest. About your suggestion, we can send multiple select selection in form of string with comma delimited items however there is a case that item contains comma. That may cause confusion so we determine to stick with array(). And actually from the array(), we can do more thing than a simple string for example: remove a selected item or adding more, or sorting items.

KoolReport commented on Jun 14, 2018

You know what, actually you can do this:

Let say you have multiple select for selecting a list of platform, the possible options are ['Window','Linnux','MacOs'], when user select some of options, could be ['Window','Linux'] which you will receive as array in $this->params["platforms"], you can do the filter like this in SQL statement:

$this->src("data")
->query("SELECT * FROM users WHERE platform IN :platforms")
->params(array(
    ":platforms"=>$this->params["platforms"]
))

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