KoolReport's Forum

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

Dashboard with multiple selections in sql query #3148

Closed John opened this topic on on Sep 15, 2023 - 3 comments

John commented on Sep 15, 2023

I use a select2 widget (multiple) and when i select more than 1 values, my query below doesn't work.

protected function value()
    $range = $this->sibling("DateRangeBox")->value();
$program = $this->sibling("MultiProgramBox")->value();	//this is the select2 widget	
    return MYDB::table("mytable1")->count()
		->leftjoin('mytable2', 'mytable1.id', '=', 'mytable2.id')
		<....other mysql query here....>
		->where("mytable2.program",  'like', $program)     //i also tried wherein...
		->whereBetween("mytable2.date", $range)   //this works fine

I think it is something with arrays.. i saw some forum articles but i can't implement the suggestions in dashboard package. Can you help?

Sebastian Morales commented on Sep 18, 2023

Pls try to use "IN" instead of "LIKE" because $program is an array:

->where("mytable2.program", 'IN', $program)
John commented on Sep 18, 2023

Thanks, I tried this (i also tried wherein) but sql does not accept it. An error shows: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax I think now it is something with NULL

John commented on Sep 18, 2023

I added the code below for handling null values and now it seems to work! if (empty($program)) $program = array("All")

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