user31465278
user31465278

Reputation: 41

Multiple AND, OR statements

Hello I would like to know if the following code could be extended with another 'AND', 'OR' statement or does it need another 'IF' statement ?

if (in_array("juliette_geinformeerd", $opts)){
$where .= " AND juliette_geinformeerd = 1 ";
}

I tryed:

if (in_array("juliette_geinformeerd", $opts)){
$where .= " AND juliette_geinformeerd = 1 " . "OR juliette_geinformeerd = 2";
}

But that doesnt work.

//Update:

So this piece of code works toghether with AJAX. If you click the checkbox it updates the page and filters options. I would like to filter it on multiple statements instead of just 1 (yes or no).

Upvotes: 1

Views: 101

Answers (2)

Ravi Sharma
Ravi Sharma

Reputation: 578

You should use $where .= " AND (juliette_geinformeerd = 1 " . "OR juliette_geinformeerd = 2)";

Upvotes: 0

Ankit Aranya
Ankit Aranya

Reputation: 970

    if (in_array("juliette_geinformeerd", $opts)){
    $where .= " juliette_geinformeerd = 1 " . "OR juliette_geinformeerd = 2";
    }
// if there is a no other conditions in the where if there any condition so try to write like that:

 $where .="('juliette_geinformeerd_else = 1";   
    if (in_array("juliette_geinformeerd", $opts)){
        $where .= "and juliette_geinformeerd = 1) " . "OR juliette_geinformeerd = 2";
        }

Upvotes: 1

Related Questions