Andrew
Andrew

Reputation: 2198

AND - OR operators in php pdo

Is there OR operator in php?

I write this code but dont work becouse I use OR operator:

$trebanam = 'seme';
$trebanam1 = 'sadnice';


    # basic pdo connection (with added option for error handling)
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { 
     $statement=$db->prepare("SELECT id,vrsta,artikl,bruto_kol FROM zalihe WHERE user_id=:user_id AND vrsta=:trebanam OR vrsta=:trebanam1");
$statement->execute(array(':user_id' => $user_id, ':trebanam'=>$trebanam, ':trebanam'=>$trebanam1));
$results=$statement->fetchAll(PDO::FETCH_ASSOC);
$json=json_encode($results);
echo $json;
     }
    else { 
echo 'GRESKA 404';
    }
    ?>

So here I need to get data where vrsta = seme or vrsta = sadnice ... How I can do that? Is it possible like I try to do that?

Upvotes: 0

Views: 643

Answers (1)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

You need proper parentheses for the OR condition

WHERE user_id=:user_id AND ( vrsta=:trebanam OR vrsta=:trebanam1 )

Upvotes: 3

Related Questions