PHP中是否有OR运算符?

我写这段代码,但是由于使用OR运算符而无法正常工作:

$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';
    }
    ?>


因此,在这里我需要获取vrsta = seme或vrsta = sadnice的数据……我该怎么做?是否有可能像我尝试那样做?

最佳答案

您需要为OR条件加上适当的括号

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

09-26 17:17